You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
graceful-shutdown-go/func_shutdowner.go

25 lines
459 B

package graceful_shutdown
import (
"git.rinsvent.ru/rinsvent/gol"
"go.uber.org/zap"
"os"
"os/signal"
"syscall"
)
type FuncShutdowner struct{}
func (sh *FuncShutdowner) Wait(f func()) {
sigChan := make(chan os.Signal, 2)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigChan
gol.With(zap.String("sig", sig.String())).Info("Gracefully shutting down")
f()
}
func NewFuncShutdowner() FuncShutdowner {
return FuncShutdowner{}
}