https://github.com/ory/graceful
A best practice http server set up that supports graceful shutdown
https://github.com/ory/graceful
Last synced: 2 months ago
JSON representation
A best practice http server set up that supports graceful shutdown
- Host: GitHub
- URL: https://github.com/ory/graceful
- Owner: ory
- License: apache-2.0
- Created: 2017-05-02T21:25:03.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-08-27T10:15:40.000Z (10 months ago)
- Last Synced: 2024-10-29T16:07:16.219Z (8 months ago)
- Language: Go
- Size: 175 KB
- Stars: 189
- Watchers: 9
- Forks: 18
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# graceful
[](https://travis-ci.org/ory/graceful)
[](https://coveralls.io/github/ory/graceful?branch=master)
[](https://godoc.org/github.com/ory/graceful)[](https://slack.ory.sh/)
Best practice http server configurations and helpers for Go 1.8's http graceful
shutdown feature. Currently supports best practice configurations by:- [Cloudflare](https://blog.cloudflare.com/exposing-go-on-the-internet/)
## Usage
To install this library, do:
```sh
go get github.com/ory/graceful
```### Running Cloudflare Config with Graceful Shutdown
```go
package mainimport (
"net/http"
"log""github.com/ory/graceful"
)func main() {
server := graceful.WithDefaults(&http.Server{
Addr: ":54932",
// Handler: someHandler,
})log.Println("main: Starting the server")
if err := graceful.Graceful(server.ListenAndServe, server.Shutdown); err != nil {
log.Fatalln("main: Failed to gracefully shutdown")
}
log.Println("main: Server was shutdown gracefully")
}
```