An open API service indexing awesome lists of open source software.

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.

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)