Documentation ¶
Overview ¶
Package goodbye provides a standard way to execute code when a process exits normally or due to a signal.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ExitCode is the exit code used by the Exit function if it is called // with an exit code value of -1. ExitCode int )
Functions ¶
func Exit ¶
Exit executes all of the registered exit handlers.
The handlers may use the IsNormalExit function and the signal provided to the handler to check if the program is exiting normally or due to a process signal.
func IsNormalExit ¶
IsNormalExit returns true if the program is exiting as a result of the Exit function being invoked versus a process signal.
func Notify ¶
Notify begins trapping the specified signals. This function should be invoked as early as possible by the executing program.
The signals argument accepts a series of os.Signal values. Any os.Signal value in the list may be succeeded with an integer to be used as the process's exit code when the associated signal is received. By default the process will exit with an exit code of zero, indicating a graceful shutdown.
The default value for the signals variadic depends on the operating system (OS):
UNIX SIGKILL, 1, SIGHUP, 0, SIGINT, 0, SIGQUIT, 0, SIGTERM, 0 Windows SIGKILL, 1, SIGHUP, 0, os.Interrupt, 0, SIGQUIT, 0, SIGTERM, 0
func Register ¶
func Register(f ExitHandler)
Register registers a function to be invoked when this process exits normally or due to a process signal.
Handlers registered with this function are given a priority of 0.
func RegisterWithPriority ¶
func RegisterWithPriority(f ExitHandler, priority int)
RegisterWithPriority registers a function to be invoked when this process exits normally or due to a process signal.
The priority determines when an exit handler is executed. Handlers with a lower integer value execute first and higher integer values execute later. If multiple handlers share the same priority level then the handlers are invoked in the order in which they were registered.