defer fmt.Println("bye")// code zero indicates success, non-zero an error.// defer will not runos.Exit(9)
Signals
Notify causes package signal to relay incoming signals to "sigs".
If no signals are provided, all incoming signals will be relayed to "sigs".
Otherwise, just the provided signals will.
{// channel that we will get signals on it sigs :=make(chanos.Signal)// channel that we will use to shutdown the app done :=make(chanbool) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)gofunc() {// blocking till we get os.Signal<-sigs// release resources// call shutdwon functions for HTTP server, DB ... fmt.Println("\nDoing graceful shutdown")// send message to shutdown done <-true }() fmt.Println("waiting for os.Signal")// waiting internal shutdown message<-done fmt.Println("Exit")}