Documentation
¶
Overview ¶
Package graceful contains best practice http server configurations and helpers for Go 1.8's http graceful shutdown feature.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPServer ¶
type HTTPServer struct {
// ShutdownTimeout defines how long the server will wait before the shutdown is forced.
ShutdownTimeout time.Duration
*http.Server
// contains filtered or unexported fields
}
HTTPServer is a wrapper for http.Server and makes running a graceful http server easy.
func PatchHTTPServerWithCloudflareConfig ¶
func PatchHTTPServerWithCloudflareConfig(srv *http.Server) *HTTPServer
PatchHTTPServerWithCloudflareConfig patches a http.Server based on a best practice configuration from Cloudflare: https://blog.cloudflare.com/exposing-go-on-the-internet/
func (*HTTPServer) Graceful ¶
func (srv *HTTPServer) Graceful(runner func()) error
Graceful sets up graceful shutdown for the HTTPServer, or returns an error if something goes wrong.
if err := server.Graceful(server, func () {
if err := server.ListenAndServe(); err != nil {
// ...
}
}); err != nil {
// ..
}
Click to show internal directories.
Click to hide internal directories.