func Serve(srv *http.Server, l net.Listener, timeout time.Duration) error {
	return run(srv, l, timeout, make(chan os.Signal, 1))
}
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"
	"os/signal"
	"syscall"
	"time"
)
func Run(addr string, timeout time.Duration, n http.Handler) {
	srv := &http.Server{Addr: addr, Handler: n}
	err := ListenAndServe(srv, timeout)
	if err != nil {
		if opErr, ok := err.(*net.OpError); !ok || (ok && opErr.Op != "accept") {
			logger := log.New(os.Stdout, "[graceful] ", 0)
			logger.Fatal(err)
		}
	}
}
func ListenAndServe(srv *http.Server, timeout time.Duration) error {
	addr := srv.Addr
	if addr == "" {
		addr = ":http"
	}
	l, err := net.Listen("tcp", addr)
	if err != nil {
		return err
	}
	return run(srv, l, timeout, make(chan os.Signal, 1))
}
func ListenAndServeTLS(srv *http.Server, certFile, keyFile string, timeout time.Duration) error {
	addr := srv.Addr
	if addr == "" {
		addr = ":https"
	}
	config := &tls.Config{}
	if srv.TLSConfig != nil {
		*config = *srv.TLSConfig
	}
	if config.NextProtos == nil {
		config.NextProtos = []string{"http/1.1"}
	}
	var err error
	config.Certificates = make([]tls.Certificate, 1)
	config.Certificates[0], err = tls.LoadX509KeyPair(certFile, keyFile)
	if err != nil {
		return err
	}
	conn, err := net.Listen("tcp", addr)
	if err != nil {
		return err
	}
	tlsListener := tls.NewListener(conn, config)
	return run(srv, tlsListener, timeout, make(chan os.Signal, 1))
}