Package manners provides a wrapper for a standard net/http server that ensures all active HTTP client have completed their current request before the server shuts down.

It can be used a drop-in replacement for the standard http package, or can wrap a pre-configured Server.


http.Handle("/hello", func(w http.ResponseWriter, r *http.Request) {

log.Fatal(manners.ListenAndServe(":8080", nil))

or for a customized server:

s := manners.NewWithServer(&http.Server{
	Addr:           ":8080",
	Handler:        myHandler,
	ReadTimeout:    10 * time.Second,
	WriteTimeout:   10 * time.Second,
	MaxHeaderBytes: 1 << 20,

The server will shut down cleanly when the Close() method is called:

go func() {
	sigchan := make(chan os.Signal, 1)
	signal.Notify(sigchan, os.Interrupt, os.Kill)
	log.Info("Shutting down...")

http.Handle("/hello", myHandler)
log.Fatal(manners.ListenAndServe(":8080", nil))

manners is referenced in 1 repository