func Serve(server *http.Server, l net.Listener, timeout time.Duration) error {
	srv := &Server{Timeout: timeout, Server: server, Logger: DefaultLogger()}
	return srv.Serve(l)
}
Serve is equivalent to http.Server.Serve 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{}
}
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)
		}
	}
}
func RunWithErr(addr string, timeout time.Duration, n http.Handler) error {
	srv := &Server{
		Timeout:      timeout,
		TCPKeepAlive: 3 * time.Minute,
		Server:       &http.Server{Addr: addr, Handler: n},
		Logger:       DefaultLogger(),
	}
	return srv.ListenAndServe()
}
func ListenAndServe(server *http.Server, timeout time.Duration) error {
	srv := &Server{Timeout: timeout, Server: server, Logger: DefaultLogger()}
	return srv.ListenAndServe()
}
func (srv *Server) ListenAndServe() error {
	addr := srv.Addr
	if addr == "" {
		addr = ":http"
	}
	conn, err := srv.newTCPListener(addr)
	if err != nil {
		return err
	}
	return srv.Serve(conn)
}
func ListenAndServeTLS(server *http.Server, certFile, keyFile string, timeout time.Duration) error {
	srv := &Server{Timeout: timeout, Server: server, Logger: DefaultLogger()}
	return srv.ListenAndServeTLS(certFile, keyFile)
}
func (srv *Server) ListenTLS(certFile, keyFile string) (net.Listener, error) {
	addr := srv.Addr
	if addr == "" {
		addr = ":https"
	}
	config := &tls.Config{}
	if srv.TLSConfig != nil {
		*config = *srv.TLSConfig
	}
	var err error
	if certFile != "" && keyFile != "" {
		config.Certificates = make([]tls.Certificate, 1)
		config.Certificates[0], err = tls.LoadX509KeyPair(certFile, keyFile)
		if err != nil {
			return nil, err
		}
	}
	enableHTTP2ForTLSConfig(config)
	conn, err := srv.newTCPListener(addr)
	if err != nil {
		return nil, err
	}
	srv.TLSConfig = config
	tlsListener := tls.NewListener(conn, config)
	return tlsListener, nil
}
func enableHTTP2ForTLSConfig(t *tls.Config) {
	if TLSConfigHasHTTP2Enabled(t) {
		return
	}
	t.NextProtos = append(t.NextProtos, "h2")
}
func TLSConfigHasHTTP2Enabled(t *tls.Config) bool {
	for _, value := range t.NextProtos {
		if value == "h2" {
			return true
		}
	}
	return false
}
func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error {
	l, err := srv.ListenTLS(certFile, keyFile)
	if err != nil {
		return err
	}
	return srv.Serve(l)
}
func (srv *Server) ListenAndServeTLSConfig(config *tls.Config) error {
	addr := srv.Addr
	if addr == "" {
		addr = ":https"
	}
	conn, err := srv.newTCPListener(addr)
	if err != nil {
		return err
	}
	srv.TLSConfig = config
	tlsListener := tls.NewListener(conn, config)
	return srv.Serve(tlsListener)
}