Terminate Golang App
channel to terminate
在 main.go中, 创建一个channel接收os.Signal
sigChan := make(chan os.Signal, 1)
// ctrl+c->SIGINT, kill -9 -> SIGKILL
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGKILL)
在main.go快结束的位置,加上
<-sigChan
log.Info("exit")
如果用户有发送kill -9 或者ctrl+c, 会接收到这个信号。