main.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package main
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "go-common/app/interface/main/app-resource/conf"
  9. "go-common/app/interface/main/app-resource/grpc"
  10. "go-common/app/interface/main/app-resource/http"
  11. absvr "go-common/app/interface/main/app-resource/service/abtest"
  12. auditsvr "go-common/app/interface/main/app-resource/service/audit"
  13. broadcastsvr "go-common/app/interface/main/app-resource/service/broadcast"
  14. domainsvr "go-common/app/interface/main/app-resource/service/domain"
  15. guidesvc "go-common/app/interface/main/app-resource/service/guide"
  16. modulesvr "go-common/app/interface/main/app-resource/service/module"
  17. "go-common/app/interface/main/app-resource/service/notice"
  18. "go-common/app/interface/main/app-resource/service/param"
  19. pingsvr "go-common/app/interface/main/app-resource/service/ping"
  20. pluginsvr "go-common/app/interface/main/app-resource/service/plugin"
  21. showsvr "go-common/app/interface/main/app-resource/service/show"
  22. sidesvr "go-common/app/interface/main/app-resource/service/sidebar"
  23. "go-common/app/interface/main/app-resource/service/splash"
  24. staticsvr "go-common/app/interface/main/app-resource/service/static"
  25. "go-common/app/interface/main/app-resource/service/version"
  26. whitesvr "go-common/app/interface/main/app-resource/service/white"
  27. ecode "go-common/library/ecode/tip"
  28. "go-common/library/log"
  29. "go-common/library/net/http/blademaster/middleware/auth"
  30. "go-common/library/net/trace"
  31. )
  32. func main() {
  33. flag.Parse()
  34. if err := conf.Init(); err != nil {
  35. log.Error("conf.Init() error(%v)", err)
  36. panic(err)
  37. }
  38. // init log
  39. log.Init(conf.Conf.Log)
  40. defer log.Close()
  41. log.Info("app-resource start")
  42. // init trace
  43. trace.Init(conf.Conf.Tracer)
  44. defer trace.Close()
  45. // ecode init
  46. ecode.Init(conf.Conf.Ecode)
  47. // service init
  48. svr := initService(conf.Conf)
  49. http.Init(conf.Conf, svr)
  50. grpcSvr, err := grpc.New(nil, svr)
  51. if err != nil {
  52. panic(err)
  53. }
  54. // init pprof conf.Conf.Perf
  55. // init signal
  56. c := make(chan os.Signal, 1)
  57. signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
  58. for {
  59. s := <-c
  60. log.Info("app-resource get a signal %s", s.String())
  61. switch s {
  62. case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
  63. grpcSvr.Shutdown(context.TODO())
  64. log.Info("app-resource exit")
  65. return
  66. case syscall.SIGHUP:
  67. // TODO reload
  68. default:
  69. return
  70. }
  71. }
  72. }
  73. // initService init services.
  74. func initService(c *conf.Config) (svr *http.Server) {
  75. svr = &http.Server{
  76. AuthSvc: auth.New(nil),
  77. // init self service,
  78. PgSvr: pluginsvr.New(c),
  79. PingSvr: pingsvr.New(c),
  80. SideSvr: sidesvr.New(c),
  81. VerSvc: version.New(c),
  82. ParamSvc: param.New(c),
  83. NtcSvc: notice.New(c),
  84. SplashSvc: splash.New(c),
  85. AuditSvc: auditsvr.New(c),
  86. AbSvc: absvr.New(c),
  87. ModuleSvc: modulesvr.New(c),
  88. GuideSvc: guidesvc.New(c),
  89. StaticSvc: staticsvr.New(c),
  90. DomainSvc: domainsvr.New(c),
  91. BroadcastSvc: broadcastsvr.New(c),
  92. WhiteSvc: whitesvr.New(c),
  93. ShowSvc: showsvr.New(c),
  94. }
  95. return
  96. }