Skip to content

Instantly share code, notes, and snippets.

@negasus
Created December 6, 2018 15:30
Show Gist options
  • Save negasus/8e1e2a88730c3790cb0719aeeccff064 to your computer and use it in GitHub Desktop.
Save negasus/8e1e2a88730c3790cb0719aeeccff064 to your computer and use it in GitHub Desktop.
GO graceful shutdown
var gracefulStop = make(chan os.Signal)
signal.Notify(gracefulStop, syscall.SIGTERM)
signal.Notify(gracefulStop, syscall.SIGINT)
go func() {
sig := <-gracefulStop
fmt.Printf("caught sig: %+v", sig)
fmt.Println("Wait for 2 second to finish processing")
time.Sleep(2 * time.Second)
os.Exit(0)
}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment