https://github.com/mattes/go-net
Convenience functions and wrappers around net and net/http
https://github.com/mattes/go-net
Last synced: 9 months ago
JSON representation
Convenience functions and wrappers around net and net/http
- Host: GitHub
- URL: https://github.com/mattes/go-net
- Owner: mattes
- Created: 2018-08-09T18:12:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-09T23:48:26.000Z (over 7 years ago)
- Last Synced: 2025-02-10T09:12:17.342Z (11 months ago)
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# net
[](https://godoc.org/github.com/mattes/go-net)
[](https://travis-ci.org/mattes/go-net)
Convenience functions and wrappers around `net` and `net/http` for ...
* Timeouts
* Graceful Server Shutdowns with Connection Draining
* Healthy and Ready handlers
## Example Usage
```go
package main
import (
"net/http"
"github.com/mattes/go-net/server"
)
func main() {
server.IsBehindGoogleLoadBalancer() // optional
mux := http.NewServeMux()
// add handlers ...
// Creates a new Server with /health and /ready handlers
// which gracefully shuts down on SIGINT or SIGTERM
log.Fatal(server.ListenAndServe(":8080", mux))
}
```
### Health check vs Ready check
| | Health | Ready |
|-----------------|--------|-------|
| Running | 200 | 200 |
| Shutting down | 200 | 503 |
## Good Reads
* https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/
* https://blog.cloudflare.com/exposing-go-on-the-internet/