main.go 1007 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "time"
  8. "go-common/app/interface/main/answer/conf"
  9. "go-common/app/interface/main/answer/http"
  10. ecode "go-common/library/ecode/tip"
  11. "go-common/library/log"
  12. "go-common/library/queue/databus/report"
  13. "go-common/library/text/translate/chinese"
  14. )
  15. func main() {
  16. flag.Parse()
  17. if err := conf.Init(); err != nil {
  18. panic(err)
  19. }
  20. log.Init(conf.Conf.Log)
  21. defer log.Close()
  22. ecode.Init(conf.Conf.Ecode)
  23. chinese.Init()
  24. http.Init(conf.Conf)
  25. report.InitUser(conf.Conf.Report)
  26. // signal handler
  27. log.Info("answer-interface start")
  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("answer get a signal %s", s.String())
  33. switch s {
  34. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
  35. time.Sleep(time.Second * 2)
  36. log.Info("answer-interface exit")
  37. return
  38. case syscall.SIGHUP:
  39. // TODO reload
  40. default:
  41. return
  42. }
  43. }
  44. }