https://github.com/dronezzzko/easyshutdown
Gracefully shutdown your Go services in just one line
https://github.com/dronezzzko/easyshutdown
go golang graceful-shutdown gracefully grpc k8s kubernetes microservices opentelemetry services
Last synced: 5 months ago
JSON representation
Gracefully shutdown your Go services in just one line
- Host: GitHub
- URL: https://github.com/dronezzzko/easyshutdown
- Owner: dronezzzko
- License: mit
- Created: 2023-02-02T19:15:43.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-15T08:32:21.000Z (almost 3 years ago)
- Last Synced: 2024-06-20T16:32:49.311Z (almost 2 years ago)
- Topics: go, golang, graceful-shutdown, gracefully, grpc, k8s, kubernetes, microservices, opentelemetry, services
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/dronezzzko/easyshutdown/actions/workflows/linters.yml)
# easyshutdown
Gracefully shutdown your Go services in just one line.
This package supports:
- HTTP and HTTPS servers
- GRPC server
- OpenTelemetry tracers
- And more
## Usage
### Simple example
```go
package main
import (
"log"
"net/http"
es "github.com/dronezzzko/easyshutdown"
)
func main() {
srv := &http.Server{
Addr: ":8080",
}
go func() {
log.Println("starting HTTP server", srv.Addr)
if err := srv.ListenAndServe(); err != nil {
log.Fatalf("HTTP server stopped: %s\n", err.Error())
}
}()
sd, _ := es.NewShutdown(
es.WithHTTPServer(srv),
)
sd.Graceful()
}
```
```terminal
go run .
```
Press ``ctrl+c``:
```
2023/02/04 19:25:04 starting HTTP server :8080
easyshutdown 2023/02/04 19:25:05 Shutting down HTTP/HTTPS server
2023/02/04 19:25:08 HTTP server stopped: http: Server closed
exit status 1
```
Also see [options.go](options.go) for all available options and supported services.