Skip to content
Go framework for well-behaving commands
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci [CircleCI] Use Go 1.12 base image to build Mar 18, 2019
test Remove dependencies on cobra Oct 21, 2018
testdata Rename the project from cmd to well. Oct 20, 2018
.gitignore ignore go.sum Dec 19, 2018
AUTHORS Update docs. Sep 6, 2016
CHANGELOG.md Bump version to 1.8.1 Oct 21, 2018
DESIGN.md DESIGN.md: improve readability Aug 28, 2018
LICENSE Update docs. Sep 6, 2016
README.md [CircleCI] Use Go 1.12 base image to build Mar 18, 2019
default.go Rename the project from cmd to well. Oct 20, 2018
doc.go Rename the project from cmd to well. Oct 20, 2018
env.go Rename the project from cmd to well. Oct 20, 2018
env_test.go Rename the project from cmd to well. Oct 20, 2018
example_test.go Add support for github.com/spf13/{pflag,vivper} Oct 20, 2018
exec.go Rename the project from cmd to well. Oct 20, 2018
exec_test.go Rename the project from cmd to well. Oct 20, 2018
go.mod Remove dependencies on cobra Oct 21, 2018
graceful.go
graceful_test.go
graceful_unix.go
graceful_unix_test.go Rename the project from cmd to well. Oct 20, 2018
graceful_windows.go Rename the project from cmd to well. Oct 20, 2018
http.go Fix Oct 20, 2018
http_17.go Use http.Server.Shutdown for Go 1.8+ Oct 20, 2018
http_test.go
idgen.go Rename the project from cmd to well. Oct 20, 2018
idgen_test.go Rename the project from cmd to well. Oct 20, 2018
jsonlog.go Rename the project from cmd to well. Oct 20, 2018
log.go
log_test.go Rename the project from cmd to well. Oct 20, 2018
logfile.go
logfile_windows.go Rename the project from cmd to well. Oct 20, 2018
reqid.go
reqid_test.go Rename the project from cmd to well. Oct 20, 2018
server.go Rename the project from cmd to well. Oct 20, 2018
server_test.go Rename the project from cmd to well. Oct 20, 2018
signal.go Rename the project from cmd to well. Oct 20, 2018
sigpipe.go Rename the project from cmd to well. Oct 20, 2018
sigpipe_windows.go
stopsig.go Rename the project from cmd to well. Oct 20, 2018
stopsig_windows.go
systemd.go Rename the project from cmd to well. Oct 20, 2018
systemd_test.go

README.md

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

You can’t perform that action at this time.