graceful

Source ยป

graceful tries to properly shut down a web server upon interrupts.

graceful.go

Example

package main

import (
	"log"
	"net/http"
	"os"

	"github.com/esote/graceful"
)

func main() {
	srv := &http.Server{
		Handler: http.HandlerFunc(myHandler),
	}

	graceful.Graceful(srv, func() {
		if err := srv.ListenAndServe(); err != http.ErrServerClosed {
			log.Fatal(err)
		}
	}, os.Interrupt)
}