main.go 987 B

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