main.go 920 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/job/main/coupon/conf"
  8. "go-common/app/job/main/coupon/http"
  9. "go-common/app/job/main/coupon/service"
  10. "go-common/library/log"
  11. )
  12. var (
  13. srv *service.Service
  14. )
  15. func main() {
  16. flag.Parse()
  17. if err := conf.Init(); err != nil {
  18. log.Error("conf.Init() error(%v)", err)
  19. panic(err)
  20. }
  21. // init log
  22. log.Init(conf.Conf.Log)
  23. defer log.Close()
  24. log.Info("coupon start")
  25. // service init
  26. srv = service.New(conf.Conf)
  27. http.Init(conf.Conf, srv)
  28. // init pprof conf.Conf.Perf
  29. // init signal
  30. c := make(chan os.Signal, 1)
  31. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  32. for {
  33. s := <-c
  34. log.Info("coupon get a signal %s", s.String())
  35. switch s {
  36. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  37. log.Info("coupon exit")
  38. srv.Close()
  39. return
  40. case syscall.SIGHUP:
  41. default:
  42. return
  43. }
  44. }
  45. }