http.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package http
  2. import (
  3. "go-common/app/interface/main/app-resource/conf"
  4. absvr "go-common/app/interface/main/app-resource/service/abtest"
  5. auditsvr "go-common/app/interface/main/app-resource/service/audit"
  6. broadcastsvr "go-common/app/interface/main/app-resource/service/broadcast"
  7. domainsvr "go-common/app/interface/main/app-resource/service/domain"
  8. guidesvc "go-common/app/interface/main/app-resource/service/guide"
  9. modulesvr "go-common/app/interface/main/app-resource/service/module"
  10. "go-common/app/interface/main/app-resource/service/notice"
  11. "go-common/app/interface/main/app-resource/service/param"
  12. pingsvr "go-common/app/interface/main/app-resource/service/ping"
  13. pluginsvr "go-common/app/interface/main/app-resource/service/plugin"
  14. showsvr "go-common/app/interface/main/app-resource/service/show"
  15. sidesvr "go-common/app/interface/main/app-resource/service/sidebar"
  16. "go-common/app/interface/main/app-resource/service/splash"
  17. staticsvr "go-common/app/interface/main/app-resource/service/static"
  18. "go-common/app/interface/main/app-resource/service/version"
  19. whitesvr "go-common/app/interface/main/app-resource/service/white"
  20. "go-common/library/log"
  21. bm "go-common/library/net/http/blademaster"
  22. "go-common/library/net/http/blademaster/middleware/auth"
  23. )
  24. var (
  25. // depend service
  26. authSvc *auth.Auth
  27. // self service
  28. pgSvr *pluginsvr.Service
  29. pingSvr *pingsvr.Service
  30. sideSvr *sidesvr.Service
  31. verSvc *version.Service
  32. paramSvc *param.Service
  33. ntcSvc *notice.Service
  34. splashSvc *splash.Service
  35. auditSvc *auditsvr.Service
  36. abSvc *absvr.Service
  37. moduleSvc *modulesvr.Service
  38. guideSvc *guidesvc.Service
  39. staticSvc *staticsvr.Service
  40. domainSvc *domainsvr.Service
  41. whiteSvc *whitesvr.Service
  42. showSvc *showsvr.Service
  43. broadcastSvc *broadcastsvr.Service
  44. )
  45. type Server struct {
  46. // depend service
  47. AuthSvc *auth.Auth
  48. // self service
  49. PgSvr *pluginsvr.Service
  50. PingSvr *pingsvr.Service
  51. SideSvr *sidesvr.Service
  52. VerSvc *version.Service
  53. ParamSvc *param.Service
  54. NtcSvc *notice.Service
  55. SplashSvc *splash.Service
  56. AuditSvc *auditsvr.Service
  57. AbSvc *absvr.Service
  58. ModuleSvc *modulesvr.Service
  59. GuideSvc *guidesvc.Service
  60. StaticSvc *staticsvr.Service
  61. DomainSvc *domainsvr.Service
  62. WhiteSvc *whitesvr.Service
  63. ShowSvc *showsvr.Service
  64. BroadcastSvc *broadcastsvr.Service
  65. }
  66. // Init is
  67. func Init(c *conf.Config, svr *Server) {
  68. initService(c, svr)
  69. // init external router
  70. engineOut := bm.DefaultServer(c.BM.Outer)
  71. outerRouter(engineOut)
  72. // init Outer server
  73. if err := engineOut.Start(); err != nil {
  74. log.Error("engineOut.Start() error(%v) | config(%v)", err, c)
  75. panic(err)
  76. }
  77. }
  78. // initService init services.
  79. func initService(c *conf.Config, svr *Server) {
  80. // init self service
  81. authSvc = svr.AuthSvc
  82. pgSvr = svr.PgSvr
  83. pingSvr = svr.PingSvr
  84. sideSvr = svr.SideSvr
  85. verSvc = svr.VerSvc
  86. paramSvc = svr.ParamSvc
  87. ntcSvc = svr.NtcSvc
  88. splashSvc = svr.SplashSvc
  89. auditSvc = svr.AuditSvc
  90. abSvc = svr.AbSvc
  91. moduleSvc = svr.ModuleSvc
  92. guideSvc = svr.GuideSvc
  93. staticSvc = svr.StaticSvc
  94. domainSvc = svr.DomainSvc
  95. broadcastSvc = svr.BroadcastSvc
  96. whiteSvc = svr.WhiteSvc
  97. showSvc = svr.ShowSvc
  98. }
  99. // outerRouter init outer router api path.
  100. func outerRouter(e *bm.Engine) {
  101. e.Ping(ping)
  102. r := e.Group("/x/resource")
  103. {
  104. r.GET("/plugin", plugin)
  105. r.GET("/sidebar", authSvc.GuestMobile, sidebar)
  106. r.GET("/topbar", topbar)
  107. r.GET("/abtest", abTest)
  108. r.GET("/abtest/v2", abTestV2)
  109. r.GET("/abtest/abserver", authSvc.GuestMobile, abserver)
  110. m := r.Group("/module")
  111. {
  112. m.POST("", module)
  113. m.POST("/list", list)
  114. }
  115. g := r.Group("/guide", authSvc.GuestMobile)
  116. {
  117. g.GET("/interest", interest)
  118. g.GET("/interest2", interest2)
  119. }
  120. r.GET("/static", getStatic)
  121. r.GET("/domain", domain)
  122. r.GET("/broadcast/servers", serverList)
  123. r.GET("/white/list", whiteList)
  124. r.GET("/show/tab", authSvc.GuestMobile, tabs)
  125. }
  126. v := e.Group("/x/v2/version")
  127. {
  128. v.GET("", getVersion)
  129. v.GET("/update", versionUpdate)
  130. v.GET("/update.pb", versionUpdatePb)
  131. v.GET("/so", versionSo)
  132. v.GET("/rn/update", versionRn)
  133. }
  134. p := e.Group("/x/v2/param", authSvc.GuestMobile)
  135. {
  136. p.GET("", getParam)
  137. }
  138. n := e.Group("/x/v2/notice", authSvc.GuestMobile)
  139. {
  140. n.GET("", getNotice)
  141. }
  142. s := e.Group("/x/v2/splash")
  143. {
  144. s.GET("", splashs)
  145. s.GET("/birthday", birthSplash)
  146. s.GET("/list", authSvc.GuestMobile, splashList)
  147. }
  148. a := e.Group("/x/v2/audit")
  149. {
  150. a.GET("", audit)
  151. }
  152. }