A simple utility for creating Go contexts that automatically cancel on system signals (SIGINT, SIGTERM).
go get github.com/bulatsan/gracectx-go
package main
import (
"fmt"
"github.com/bulatsan/gracectx-go"
)
func main() {
// Create a new context that will be canceled on SIGINT or SIGTERM
ctx, cancel := gracectx.New()
defer cancel()
fmt.Println("Running... Press Ctrl+C to exit")
<-ctx.Done() // Wait for termination signal
fmt.Println("Shutting down gracefully")
}ctx, cancel := gracectx.Wrap(context.Background())
defer cancel()See LICENSE file for details.