// Created on savesnippets.com · https://savesnippets.com/0F0UOHcCcF1CBO package main import ( "context" "fmt" "os/signal" "syscall" "time" ) func main() { ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer stop() // restore default handlers fmt.Println("running — press Ctrl-C to stop") select { case <-time.After(60 * time.Second): fmt.Println("done by timeout") case <-ctx.Done(): fmt.Println("got signal:", ctx.Err()) // graceful shutdown logic here } }