This commit is contained in:
Evgeniy Kulikov 2019-11-06 15:33:46 +03:00
commit b4ac08d341
No known key found for this signature in database
GPG key ID: BF6AEE0A2A699BF2
9 changed files with 723 additions and 0 deletions

24
grace.go Normal file
View file

@ -0,0 +1,24 @@
package main
import (
"context"
"os"
"os/signal"
"syscall"
"go.uber.org/zap"
)
// newGracefulContext returns graceful context
func newGracefulContext(l *zap.Logger) context.Context {
ctx, cancel := context.WithCancel(context.Background())
go func() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
sig := <-ch
l.Info("received signal",
zap.String("signal", sig.String()))
cancel()
}()
return ctx
}