All Projects → shogo82148 → go-gracedown

shogo82148 / go-gracedown

Licence: MIT License
No description, website, or topics provided.

Programming Languages

go
31211 projects - #10 most used programming language

go-gracedown

Package go-gracedown provides a library that makes it easy to build a HTTP server that can be shutdown gracefully (that is, without dropping any connections).

SYNOPSIS

import (
  "os"
  "os/signal"

  "github.com/shogo82148/go-gracedown"
)

func main() {
  go func() {
    for {
      s := <-signal_chan
        if s == syscall.SIGTERM {
          gracedown.Close() // trigger graceful shutdown
        }
    }
  }()

  handler := MyHTTPHandler()
  gracedown.ListenAndServe(":7000", handler)
}

built-in graceful shutdown support (from Go version 1.8 onward)

From Go version 1.8 onward, the HTTP Server has support for graceful shutdown. (HTTP Server Graceful Shutdown) The go-gracedown package is just a wrapper of the net/http package to maintain interface compatibility. So you should use the "net/http".Server.Shutdown method and "net/http".Server.Close method directly.

Changes

  • Go version 1.7 or less: The grace.Server.Close method keeps currently-open connections.
  • From Go version 1.8 onward: The grace.Server.Close method drops currently-open connections.

GODOC

See godoc for more information.

SEE ALSO

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].