Graceful shutdown
Cancels ctx when the first matching signal arrives. Call stop() to restore default handling. Pairs perfectly with http.Server.Shutdown.
ctx, stop := signal.NotifyContext(context.Background(),
os.Interrupt, syscall.SIGTERM)
defer stop()
go srv.ListenAndServe()
<-ctx.Done()
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
srv.Shutdown(shutdownCtx)