main.go 994 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "flag"
  4. "os"
  5. "os/signal"
  6. "syscall"
  7. "go-common/app/admin/main/answer/conf"
  8. "go-common/app/admin/main/answer/http"
  9. "go-common/app/admin/main/answer/service"
  10. "go-common/library/log"
  11. "go-common/library/net/trace"
  12. "go-common/library/text/translate/chinese"
  13. )
  14. func main() {
  15. flag.Parse()
  16. // init conf,log,trace,stat,perf.
  17. if err := conf.Init(); err != nil {
  18. panic(err)
  19. }
  20. log.Init(conf.Conf.Log)
  21. defer log.Close()
  22. trace.Init(conf.Conf.Tracer)
  23. defer trace.Close()
  24. chinese.Init()
  25. svr := service.New(conf.Conf)
  26. http.Init(conf.Conf, svr)
  27. // signal handler
  28. log.Info("answer-admin start")
  29. c := make(chan os.Signal, 1)
  30. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  31. for {
  32. s := <-c
  33. log.Info("answer-admin get a signal %s", s.String())
  34. switch s {
  35. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  36. log.Info("answer-admin exit")
  37. return
  38. case syscall.SIGHUP:
  39. // TODO reload
  40. default:
  41. return
  42. }
  43. }
  44. }