package main import ( "fmt" "os" "os/signal" "syscall" ) // SetupCloseHandler creates a 'listener' on a new goroutine which will notify the // program if it receives an interrupt from the OS. We then handle this by calling // our clean up procedure and exiting the program. func SetupCloseHandler() { c := make(chan os.Signal, 2) signal.Notify(c, os.Interrupt, syscall.SIGTERM) signal.Notify(c, os.Interrupt, syscall.SIGHUP) signal.Notify(c, os.Interrupt, syscall.SIGKILL) go func() { <-c fmt.Println("\r- Ctrl+C pressed in Terminal") os.Exit(0) }() }