Deprecated: This project has come to an end and will not receive any update.
This is a framework to create well-behaving commands.
- Context-based goroutine management.
- Signal handlers.
- Graceful stop/restart for any kind of network servers.
- Logging options.
- Enhanced http.Server.
- Ultra fast UUID-like ID generator.
- Activity tracking.
- Support for systemd socket activation.
- Support for github.com/spf13/cobra.
Go 1.11 or later, though the code is expected to work with Go 1.7.
Commands using this framework implement these external specifications:
-
-logfile FILEOutput logs to FILE instead of standard error.
-
-loglevel LEVELChange logging threshold to LEVEL. Default is
info.
LEVEL is one ofcritical,error,warning,info, ordebug. -
-logformat FORMATChange log formatter. Default is
plain.
FORMAT is one ofplain,logfmt, orjson.
-
SIGUSR1If
-logfileis specified, this signal make the program reopen the log file to cooperate with an external log rotation program.On Windows, this is not implemented.
-
SIGINTandSIGTERMThese 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
SIGINTis handled. -
SIGHUPThis 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.
-
SIGPIPEThe 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.
-
REQUEST_ID_HEADERThe 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_FDSThis is used internally for graceful restart.
-
CANCELLATION_DELAY_SECONDSAfter
SIGINTorSIGTERMreceived, the signal handler waits for the seconds before cancelling the context. The default value is 5 sec.
Read Tutorial, the design notes and API documents.
A wiki page for cobra users is also available.
github.com/cybozu-go/coiluses well with cobra.github.com/cybozu-go/aptutilgithub.com/cybozu-go/gomagithub.com/cybozu-go/transocksgithub.com/cybozu-go/usocksd
Pull requests are welcome to add your project to this list!