Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppName ¶ added in v0.2.13
func AppName() string
AppName returns the command name populated during process.Init().
func AppVersion ¶ added in v0.2.13
func AppVersion() string
AppVersion returns only the version and buildstamp populated during process.Init().
func AtExit ¶
func AtExit(f func())
AtExit registers a function to be called when `process.Exit` from this package is called.
Subsequent calls to AtExit do not overwrite previous calls, and registered functions are executed in stack order, in order to mimic the behavior of `defer`.
Since AtExit does not hook into the standard-library `os.Exit`, you must avoid using any function that calls `os.Exit` (most often `Fatal`-type logging methods).
func Context ¶
Context returns a process-level `context.Context` that is cancelled when the program receives a termination signal.
A process should start a graceful shutdown process once this context is cancelled.
This context should not be used as a parent to any requests, otherwise those requests will also be cancelled instead of being allowed to complete their work.
func Exit ¶
func Exit(status int)
Exit causes the current program to exit with the given status code.
Exit runs the sequence of functions established by `process.AtExit`, and then calls `os.Exit` with the given status.
func HangupChannel ¶
func HangupChannel() <-chan struct{}
HangupChannel provides a receiver channel that will notify the caller of when a SIGHUP signal has been received. This signal is often used by daemons to be notified of a request to reload configuration data.
If the signal handler would block trzing to send this notification, then it will treat the signal the same as any other terminating signal.
func Init ¶
Init is initialization code that provides basic functionality for processes.
Init takes as parameters version information, identifying the Command Name, Semver, and a Buildstamp. The Buildstamp could be just a timestamp, or could include a commit hash or other reference.
Init parses flags, sets up AtExit, and will start profiling if the appropriate flag is set.
It returns the `context.Context` from `process.Context()`, and a function that `main` should `defer`, which will take care of executing the queued AtExit functions.
func Quit ¶
func Quit()
Quit ends the program as soon as possible, dumping a stacktrace of all goroutines.
Quit works by injecting a `syscall.SIGQUIT` directly to the signal handler, which will cause a panic, and stacktrace of all goroutines the same as a real SIGQUIT.
If Quit cannot inject the signal, it will setup an unrecoverable panic to occur.
In all cases, Quit will not return.
func Shutdown ¶
func Shutdown() error
Shutdown starts any graceful shutdown processes waiting for `process.Context()` to be cancelled.
Shutdown works by injecting a `syscall.SIGTERM` directly to the signal handler, which will cancel the `process.Context()` the same as a real SIGTERM.
Shutdown returns an error only if it is unable to send the signal. Notably, it is not an error to call Shutdown if we have already triggered a graceful shutdown.
Shutdown does not wait for anything to finish before returning.
func Version ¶
func Version() string
Version returns the full version information populated during process.Init().
This function is intended to implement a `--version` flag, and thus returns `"cmdname version[-buildstamp]"`. It does _not_ return just the `"version[-buildstamp]"` information, for that use `AppVersion()`.
Types ¶
This section is empty.