func Run(addr string, timeout time.Duration, n http.Handler) {
	srv := &Server{
		Timeout:      timeout,
		TCPKeepAlive: 3 * time.Minute,
		Server:       &http.Server{Addr: addr, Handler: n},
	}
	if err := srv.ListenAndServe(); err != nil {
		if opErr, ok := err.(*net.OpError); !ok || (ok && opErr.Op != "accept") {
			srv.logf("%s", err)
			os.Exit(1)
		}
	}
}
Run serves the http.Handler with graceful shutdown enabled.

timeout is the duration to wait until killing active requests and stopping the server.
If timeout is 0, the server never times out. It waits for all active requests to finish.
package graceful
import (
	"crypto/tls"
	"log"
	"net"
	"net/http"
	"os"
	"sync"
	"time"
)
type Server struct {
	*http.Server
	Timeout time.Duration
	ListenLimit int
	TCPKeepAlive time.Duration
	ConnState func(net.Conn, http.ConnState)
	BeforeShutdown func() bool
	ShutdownInitiated func()
	NoSignalHandling bool
	Logger *log.Logger
	LogFunc func(format string, args ...interface{})
	Interrupted bool
	interrupt chan os.Signal
	stopLock sync.Mutex
	stopChan chan struct{}
	chanLock sync.RWMutex
	connections map[net.Conn]struct{}
	idleConnections map[net.Conn]struct{}
}