https://github.com/borislavv/go-graceful-shutdown
Implementation of graceful shutdown for golang applications.
https://github.com/borislavv/go-graceful-shutdown
golang graceful-shutdown library
Last synced: 6 months ago
JSON representation
Implementation of graceful shutdown for golang applications.
- Host: GitHub
- URL: https://github.com/borislavv/go-graceful-shutdown
- Owner: Borislavv
- License: apache-2.0
- Created: 2024-10-01T09:26:08.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-10-01T10:06:52.000Z (8 months ago)
- Last Synced: 2024-12-07T03:08:52.096Z (6 months ago)
- Topics: golang, graceful-shutdown, library
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Golang graceful shutdown
### Usage:
ctx, cancel := context.WithCancel(context.Background())
gsh := shutdown.NewGraceful(ctx, cancel)gateway, err := api.NewGateway(ctx, output, livenessProbe)
if err != nil {
return lgr.Fatal(ctx, errors.New("starting the api gateway failed"), logger.Fields{"err": err.Error()})
}dispatcher, err := event.NewDispatcher(ctx, output, livenessProbe)
if err != nil {
return lgr.Fatal(ctx, errors.New("starting the event dispatcher failed"), logger.Fields{"err": err.Error()})
}gsh.Add(1)
go func() {
defer gsh.Done()
gateway.Start()
}()gsh.Add(1)
go func() {
defer gsh.Done()
dispatcher.Start()
}()gsh.ListenCancelAndAwait()
lgr.InfoMsg(ctx, "the entire app (gateway and dispatcher) has been successfully shut down, exiting", nil)