Documentation ¶
Index ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func ContextWithStopCh ¶
ContextWithStopCh will wrap a context with a stop channel. When the provided stopCh closes, the cancel() will be called on the context. This provides a convenient way to represent a stop channel as a context.
func SetExitCode ¶
func SetExitCode(err error)
SetExitCode sets the exit code to 1 if the error is not a context.Canceled error.
func SetupExitHandler ¶
func SetupExitHandler(exitBehavior ExitBehavior) (<-chan struct{}, func())
SetupExitHandler: A stop channel is returned which is closed on receiving a shutdown signal (SIGTERM or SIGINT). If a second signal is caught, the program is terminated directly with exit code 130. SetupExitHandler also returns an exit function, this exit function calls os.Exit(...) if there is a exit code in the errorExitCodeChannel. The errorExitCodeChannel receives exit codes when SetExitCode is called or when a shutdown signal is received (only if exitBehavior is AlwaysErrCode).
Types ¶
type ExitBehavior ¶
type ExitBehavior int
ExitBehavior controls how the program should be terminated in response to a shutdown signal.
const ( // AlwaysErrCode indicates the exit code of the program should always be nonzero // and should correspond to the numeric value of the signal that was received. AlwaysErrCode ExitBehavior = iota // GracefulShutdown treats a shutdown signal as a request to exit gracefully, terminating // goroutines and returning an exit code of 0 if there are no errors during shutdown. GracefulShutdown ExitBehavior = iota )