This is a small helper Go library that exposes two types:
interrupt.Signals: All OS-specific interrupt signals. This extendsos.Interruptwithsyscall.SIGTERMin unix-like systems.interrupt.Handle: A simple function to provide interrupt signal handling on acontext.Context.
This will typically be used at the highest levels of an application:
func main() {
// Handle returns a copy of the parent Context that is marked done
// when an interrupt signal arrives or when the parent Context's
// Done channel is closed, whichever happens first.
//
// Signal handling is unregistered automatically by this function when the
// first interrupt signal arrives, which will restore the default interrupt
// signal behavior of Go programs (to exit).
ctx := interrupt.Handle(context.Background())
// Use the ctx throughout the rest of your application.
// ...
}This library is stable.
Offered under the Apache 2 license.