package main import ( "context" "fmt" "log" "os" "os/signal" "time" ) func main() { fmt.Println("Hello world!") s := Server{ port: ":9999", } go func() { s.serve() }() signCh := make(chan os.Signal) signal.Notify(signCh, os.Interrupt) signal.Notify(signCh, os.Kill) sig := <-signCh log.Println("Received terminal, graceful shutdown", sig) tc, _ := context.WithTimeout(context.Background(), 30*time.Second) s.shutdown(tc) }