well

Go framework for well-behaving commands

  • 所有者: cybozu-go/well
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

GitHub release
GoDoc
CircleCI
Go Report Card

Go Command Framework

This is a framework to create well-behaving commands.

Features

Requirements

Go 1.11 or later, though the code is expected to work with Go 1.7.

Specifications

Commands using this framework implement these external specifications:

Command-line options

  • -logfile FILE

    Output logs to FILE instead of standard error.

  • -loglevel LEVEL

    Change logging threshold to LEVEL. Default is info.
    LEVEL is one of critical, error, warning, info, or debug.

  • -logformat FORMAT

    Change log formatter. Default is plain.
    FORMAT is one of plain, logfmt, or json.

Signal Handlers

  • SIGUSR1

    If -logfile is specified, this signal make the program reopen
    the log file to cooperate with an external log rotation program.

    On Windows, this is not implemented.

  • SIGINT and SIGTERM

    These signals cancel the context of the global environment,
    and hence goroutines registered with the environment. Usually
    this will result in graceful stop of network servers, if any.

    On Windows, only SIGINT is handled.

  • SIGHUP

    This signal is used to restart network servers gracefully.
    Internally, the main (master) process restarts its child process.
    The PID of the master process thus will not change.

    There is one limitation: the location of log file cannot be changed
    by graceful restart. To change log file location, the server need
    to be (gracefully) stopped and started.

    On Windows, this is not implemented.

  • SIGPIPE

    The framework changes the way Go handles SIGPIPE slightly.
    If a program using this framework receives SIGPIPE when writing to stdout or stderr, the program exits with status code 2.
    See #15 for details.

Environment variables

  • REQUEST_ID_HEADER

    The value of this variable is used as HTTP header name.
    The HTTP header is used to track activities across services.
    The default header name is "X-Cybozu-Request-ID".

  • CYBOZU_LISTEN_FDS

    This is used internally for graceful restart.

Usage

Read Tutorial, the design notes and godoc.

A wiki page for cobra users is also available.

Real world examples

Pull requests are welcome to add your project to this list!

License

MIT

主要指标

概览
名称与所有者cybozu-go/well
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2016-08-04 07:21:30
推送于2023-03-31 07:16:13
最后一次提交
发布数18
最新版本名称v1.11.2 (发布于 2023-02-02 01:10:49)
第一版名称v1.0.0 (发布于 )
用户参与
星数126
关注者数21
派生数14
提交数173
已启用问题?
问题数12
打开的问题数0
拉请求数30
打开的拉请求数0
关闭的拉请求数5
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?