Skip to content

Instantly share code, notes, and snippets.

@hinst
Last active October 12, 2021 20:06
Show Gist options
  • Save hinst/90b54ec94e5765ef19b4 to your computer and use it in GitHub Desktop.
Save hinst/90b54ec94e5765ef19b4 to your computer and use it in GitHub Desktop.
Signal receiver for Go
package main
import (
"os"
"os/signal"
"syscall"
)
func InstallShutdownReceiver(receiver func()) {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT)
signal.Notify(c, syscall.SIGTERM)
go func() {
for currentSignal := range c {
var _ = currentSignal
receiver()
}
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment