package main import ( "flag" "os" "os/signal" "syscall" "time" "go-common/app/infra/canal/conf" "go-common/app/infra/canal/http" "go-common/app/infra/canal/service" "go-common/library/log" ) func main() { flag.Parse() if err := conf.Init(); err != nil { panic(err) } log.Init(conf.Conf.Log) defer log.Close() log.Info("canal start") canal := service.NewCanal(conf.Conf) http.Init(conf.Conf, canal) ch := make(chan os.Signal, 1) signal.Notify(ch, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) for { s := <-ch log.Info("canal get a signal %s", s.String()) switch s { case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT: canal.Close() log.Info("canal exit") time.Sleep(time.Second) return case syscall.SIGHUP: default: return } } }