Skip to content

Instantly share code, notes, and snippets.

@syossan27
Created February 13, 2018 04:40
Show Gist options
  • Save syossan27/4b495db5b60f592eb9e47a4f44ad2ba8 to your computer and use it in GitHub Desktop.
Save syossan27/4b495db5b60f592eb9e47a4f44ad2ba8 to your computer and use it in GitHub Desktop.
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt, syscall.SIGTERM)
go func(ln net.Listener, c chan os.Signal) {
sig := <-c
log.Printf("Caught signal %s: shutting down.", sig)
ln.Close()
os.Exit(0)
}(ln, sigc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment