Help us shape the future of Go! Take the 2026 Go Developer Survey

graceful

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2017 License: Apache-2.0 Imports: 7 Imported by: 117

README

graceful

Build Status Coverage Status

Best practice http server configurations and helpers for Go 1.8's http graceful shutdown feature. Currently supports best practice configurations by:

Usage

To install this library, do:

go get github.com/ory/graceful
Running Cloudflare Config with Graceful Shutdown
package main

import "github.com/ory/graceful"
import "net/http"

func main() {
    server := graceful.PatchHTTPServerWithCloudflareConfig(&http.Server{
        Addr: ":54932",
        // Handler: someHandler,
    })

    if err := server.Graceful(func () {
        if err := server.ListenAndServe(); err != nil {
            // ...
        }
    }); err != nil {
        // ...
    }
}

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 {
  	   // ..
  }

Jump to

Keyboard shortcuts

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