package main import ( "fmt" "os" "os/signal" "syscall" "time" ) func main() { //create channel that can receive OS signals ch := make(chan os.Signal) //Submit channel to the notify signal signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT) //a go function to monitor signals in the background go func() { for sig := range ch { switch sig { case syscall.SIGTERM: fmt. Println("sigterm received') os. Exit(0) case syscall.SIGINT: fmt.Println("sigint received') oS.Exit(0) } } }() time.Sleep(time.Minute) } |