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
}
}
Create a free account and build your private vault. Share publicly whenever you want.