main.go 1003 B

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