8000 GitHub - ojizero/gracefully: Handling your Go servers with grace.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ojizero/gracefully

Folders and files

< 8000 span class="text-bold">NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gracefully

Handling your Go servers with grace.

Usage

Under the hood this relies directly on http.Server's Shutdown() method but provides it in a boilerplate free way.

Install the package

go get github.com/ojizero/gracefully

Replace your application's startup point with the following

import (
  "net/http"

  "github.com/ojizero/gracefully"
)

func main() {
  var h http.Handler // ... build your http handler
  var addr string    // set the address to listen to
  gracefully.ServeHandler(h, addr)
}

And in case you have an http.Server instance you can use

import (
  "net/http"

  "github.com/ojizero/gracefully"
)

func main() {
  var srv http.Server // ... build your http server
  gracefully.Serve(srv)
}
0