Skip to content

Instantly share code, notes, and snippets.

@dmotylev
Created January 22, 2019 10:30
Show Gist options
  • Save dmotylev/60723fb355e4ad22a073e19cdc4393c1 to your computer and use it in GitHub Desktop.
Save dmotylev/60723fb355e4ad22a073e19cdc4393c1 to your computer and use it in GitHub Desktop.
service helpers
func WaitShutdownRequest(f func(os.Signal)) {
signals := make(chan os.Signal)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
f(<-signals)
}
func CleanUp(closers ...func()) {
for _, f := range closers {
f()
}
}
func FatalIfError(err error, lastWords string, closers ...func()) {
if err == nil {
return
}
CleanUp(closers...)
fmt.Printf("%s: %s", lastWords, err)
os.Exit(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment