Created
January 22, 2019 10:30
-
-
Save dmotylev/60723fb355e4ad22a073e19cdc4393c1 to your computer and use it in GitHub Desktop.
service helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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