Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetExitCode ¶
func SetExitCode(err error)
SetExitCode sets the exit code to 1 if the error is not a context.Canceled error.
func SetExitCodeValue ¶
func SetExitCodeValue(code int)
SetExitCode sets the exit code to 1 if the error is not a context.Canceled error.
func SetupExitHandler ¶
func SetupExitHandler(parentCtx context.Context, exitBehavior ExitBehavior) (context.Context, func())
SetupExitHandler: A context is returned which is canceled 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 )