httpshutdown icon indicating copy to clipboard operation
httpshutdown copied to clipboard

how to do graceful shutdown with net/http (maybe)

package httpshutdown import "github.com/kr/httpshutdown"

Package httpshutdown illustrates a possible way to do graceful shutdown
with net/http. This code is untested.

TYPES

type Server struct { Server *http.Server // contains filtered or unexported fields } Serve wraps the net/http Server and performs graceful shutdown.

func (s *Server) Serve(l net.Listener) error Serve calls Serve on the underlying http Server, but wraps l in another net.Listener that synchronises open connections with Wait.

func (s *Server) Wait() Wait waits for all open connections in s to close.