gracefulserver

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2017 License: MIT Imports: 7 Imported by: 1

README

gracefulserver

Boilerplate for starting an HTTP server in Go with graceful shutdown

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger = func(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		start := time.Now()
		next.ServeHTTP(w, r)
		log.Printf("Served %s for %q in %v", r.URL, r.UserAgent(), time.Since(start))
	})

}

Logger is the logging middleware for gracefulserver. By default it logs the URL, UserAgent, and duration of requests with Go standard logger.

View Source
var (
	// Timeout is the amount of time the server will wait for requests to finish during shutdown
	Timeout = 5 * time.Second
)

Functions

func Serve

func Serve(handler http.Handler)

Serve starts an HTTP listener on the port specified by environmental variable PORT (8080 if not set). Requests will be logged by the Logger middleware. Serve blocks until SIGINT or SIGTERM is received and the listener is closed.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL