Documentation ¶
Index ¶
Constants ¶
View Source
const ErrSignalTrapped = "signal trapped"
ErrSignalTrapped is returned by the SignalTrap.Wait when the expected signals caught.
Variables ¶
This section is empty.
Functions ¶
func SetupSignalHandler ¶
func SetupSignalHandler() (stopCh <-chan struct{})
SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned which is closed on one of these signals. If a second signal is caught, the program is terminated with exit code 1.
Types ¶
type SignalTrap ¶
SignalTrap wraps os.Signal channel to provide high level API above it.
trap := make(chan os.Signal) signal.Notify(trap, os.Interrupt) SignalTrap(trap).Wait(context.Background())
func Termination ¶
func Termination() SignalTrap
Termination returns trap for termination signals.
server := new(http.Server) go log.Println(server.ListenAndServe()) err := sync.Termination().Wait(context.Background()) if err == sync.ErrSignalTrapped { log.Println("shutting down the server", server.Shutdown(context.Background())) }
Click to show internal directories.
Click to hide internal directories.