go get github.com/msrexe/grace
func main() {
go func() {
grace.ShutdownWithTimeout(5*time.Second, func() {
log.Println("Application gracefully stopped")
})
}()
for {
log.Println("Hello World")
time.Sleep(2 * time.Second)
}
}
For more examples, look at the example directory.