http.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/interface/main/activity/conf"
  5. "go-common/app/interface/main/activity/service/bnj"
  6. "go-common/app/interface/main/activity/service/bws"
  7. "go-common/app/interface/main/activity/service/kfc"
  8. "go-common/app/interface/main/activity/service/like"
  9. "go-common/app/interface/main/activity/service/sports"
  10. "go-common/app/interface/main/activity/service/timemachine"
  11. "go-common/library/log"
  12. bm "go-common/library/net/http/blademaster"
  13. "go-common/library/net/http/blademaster/middleware/auth"
  14. "go-common/library/net/http/blademaster/middleware/verify"
  15. )
  16. var (
  17. likeSvc *like.Service
  18. sportsSvc *sports.Service
  19. matchSvc *like.Service
  20. bwsSvc *bws.Service
  21. tmSvc *timemachine.Service
  22. bnjSvc *bnj.Service
  23. kfcSvc *kfc.Service
  24. authSvc *auth.Auth
  25. vfySvc *verify.Verify
  26. )
  27. // Init int http service
  28. func Init(c *conf.Config) {
  29. initService(c)
  30. engine := bm.DefaultServer(c.HTTPServer)
  31. outerRouter(engine)
  32. internalRouter(engine)
  33. // init Outer serve
  34. if err := engine.Start(); err != nil {
  35. log.Error("engine.Start error(%v)", err)
  36. panic(err)
  37. }
  38. }
  39. // initService init service
  40. func initService(c *conf.Config) {
  41. authSvc = auth.New(c.Auth)
  42. vfySvc = verify.New(c.Verify)
  43. likeSvc = like.New(c)
  44. sportsSvc = sports.New(c)
  45. matchSvc = like.New(c)
  46. bwsSvc = bws.New(c)
  47. tmSvc = timemachine.New(c)
  48. bnjSvc = bnj.New(c)
  49. kfcSvc = kfc.New(c)
  50. }
  51. //CloseService close all service
  52. func CloseService() {
  53. likeSvc.Close()
  54. bnjSvc.Close()
  55. kfcSvc.Close()
  56. }
  57. // outerRouter init outer router api path.
  58. func outerRouter(e *bm.Engine) {
  59. e.Ping(ping)
  60. e.Register(register)
  61. group := e.Group("/x/activity", bm.CORS())
  62. {
  63. group.GET("/subject", subject)
  64. group.POST("/vote", authSvc.User, vote)
  65. group.GET("/ltime", ltime)
  66. group.GET("/object/group", groupData)
  67. group.GET("/tag/object", tagList)
  68. group.GET("/tag/object/stats", tagStats)
  69. group.GET("/region/object", regionList)
  70. group.GET("/subject/total/stat", subjectStat)
  71. group.GET("/view/rank", viewRank)
  72. group.POST("/likeact", authSvc.User, likeAct)
  73. group.GET("/likeact/list", authSvc.Guest, likeActList)
  74. group.POST("/missiongroup/like", authSvc.User, missionLike)
  75. group.POST("/missiongroup/likeact", authSvc.User, missionLikeAct)
  76. group.GET("/missiongroup/info", authSvc.User, missionInfo)
  77. group.GET("/missiongroup/tops", missionTops)
  78. group.GET("/missiongroup/user", missionUser)
  79. group.GET("/missiongroup/rank", authSvc.User, missionRank)
  80. group.GET("/missiongroup/friends", authSvc.User, missionFriends)
  81. group.GET("/missiongroup/award", authSvc.User, missionAward)
  82. group.POST("/missiongroup/achievement", authSvc.User, missionAchieve)
  83. group.POST("/up/act", authSvc.User, storyKingAct)
  84. group.GET("/up/left", authSvc.User, storyKingLeft)
  85. group.GET("/up/list", authSvc.Guest, upList)
  86. spGroup := group.Group("/sports")
  87. {
  88. spGroup.GET("/qq", qq)
  89. spGroup.GET("/news", news)
  90. }
  91. matchGroup := group.Group("/match")
  92. {
  93. matchGroup.GET("", matchs)
  94. matchGroup.GET("/unstart", authSvc.Guest, unStart)
  95. matchGroup.POST("/cache/clear", clearCache)
  96. guGroup := matchGroup.Group("/guess")
  97. {
  98. guGroup.GET("", authSvc.User, guess)
  99. guGroup.GET("/list", authSvc.User, listGuess)
  100. guGroup.POST("/add", authSvc.User, addGuess)
  101. }
  102. foGroup := matchGroup.Group("/follow")
  103. {
  104. foGroup.GET("", authSvc.User, follow)
  105. foGroup.POST("/add", authSvc.User, addFollow)
  106. }
  107. }
  108. tmGroup := group.Group("/timemachine")
  109. {
  110. tmGroup.GET("/2018", authSvc.User, timemachine2018)
  111. tmGroup.GET("/2018/raw", authSvc.User, timemachine2018Raw)
  112. tmGroup.GET("/2018/cache", authSvc.User, timemachine2018Cache)
  113. }
  114. bwsGroup := group.Group("/bws")
  115. {
  116. bwsGroup.GET("/user", authSvc.Guest, user)
  117. bwsGroup.GET("/points", points)
  118. bwsGroup.GET("/point", point)
  119. bwsGroup.GET("/achievements", achievements)
  120. bwsGroup.GET("/achievement", achievement)
  121. bwsGroup.POST("/point/unlock", authSvc.User, unlock)
  122. bwsGroup.POST("/binding", authSvc.User, binding)
  123. bwsGroup.POST("/award", authSvc.User, award)
  124. bwsGroup.GET("/lottery", authSvc.User, lottery)
  125. bwsGroup.GET("/lottery/check", authSvc.User, lotteryCheck)
  126. bwsGroup.GET("/redis/check", authSvc.User, redisInfo)
  127. bwsGroup.GET("/key/info", authSvc.User, keyInfo)
  128. bwsGroup.GET("/admin/check", authSvc.User, adminInfo)
  129. }
  130. bnjGroup := group.Group("/bnj2019")
  131. {
  132. bnjGroup.GET("/preview", authSvc.Guest, previewInfo)
  133. // TODO remove guest check
  134. bnjGroup.GET("/timeline", authSvc.Guest, timeline)
  135. bnjGroup.POST("/fail", fail)
  136. bnjGroup.POST("/reset", authSvc.User, reset)
  137. bnjGroup.POST("/reward", authSvc.User, reward)
  138. }
  139. kfcGroup := group.Group("/kfc")
  140. {
  141. kfcGroup.GET("/info", authSvc.User, kfcInfo)
  142. kfcGroup.GET("/use", kfcUse)
  143. }
  144. }
  145. }
  146. func internalRouter(e *bm.Engine) {
  147. group := e.Group("/x/internal/activity")
  148. {
  149. group.GET("/subject", vfySvc.Verify, subject)
  150. group.POST("/vote", vfySvc.Verify, vote)
  151. group.GET("/ltime", vfySvc.Verify, ltime)
  152. group.GET("/reddot", vfySvc.Verify, redDot)
  153. group.GET("/reddot/clear", vfySvc.Verify, authSvc.Guest, clearRedDot)
  154. group.GET("/object/stat/set", vfySvc.Verify, setSubjectStat)
  155. group.GET("/view/rank/set", vfySvc.Verify, setViewRank)
  156. group.GET("/like/content/set", vfySvc.Verify, setLikeContent)
  157. group.GET("/likeact/add", vfySvc.Verify, addLikeAct)
  158. group.GET("/likeact/cache", vfySvc.Verify, likeActCache)
  159. group.GET("/oids/info", vfySvc.Verify, likeOidsInfo)
  160. spGroup := group.Group("/sports")
  161. {
  162. spGroup.GET("/qq", vfySvc.Verify, qq)
  163. spGroup.GET("/news", vfySvc.Verify, news)
  164. }
  165. mactchGroup := group.Group("/match")
  166. {
  167. mactchGroup.GET("", matchs)
  168. mactchGroup.GET("/unstart", vfySvc.Verify, unStart)
  169. mactchGroup.POST("/cache/clear", clearCache)
  170. guGroup := mactchGroup.Group("/guess")
  171. {
  172. guGroup.GET("", vfySvc.Verify, guess)
  173. guGroup.GET("/list", vfySvc.Verify, listGuess)
  174. guGroup.POST("/add", vfySvc.Verify, addGuess)
  175. }
  176. foGroup := mactchGroup.Group("/follow")
  177. {
  178. foGroup.GET("", vfySvc.Verify, follow)
  179. foGroup.POST("/add", vfySvc.Verify, addFollow)
  180. }
  181. }
  182. initGroup := group.Group("/init")
  183. {
  184. initGroup.GET("/subject", vfySvc.Verify, subjectInit)
  185. initGroup.GET("/like", vfySvc.Verify, likeInit)
  186. initGroup.GET("/likeact", vfySvc.Verify, likeActCountInit)
  187. initGroup.GET("/subject/list", vfySvc.Verify, subjectLikeListInit)
  188. }
  189. //tmGroup := group.Group("/timemachine")
  190. //{
  191. // tmGroup.GET("/start", startTmProc)
  192. // tmGroup.GET("/stop", stopTmProc)
  193. //}
  194. kfcIGroup := group.Group("/kfc")
  195. {
  196. kfcIGroup.POST("/deliver", vfySvc.Verify, deliverKfc)
  197. }
  198. group.GET("/bnj2019/time/del", delTime)
  199. }
  200. }
  201. func ping(c *bm.Context) {
  202. if err := likeSvc.Ping(c); err != nil {
  203. log.Error("activity interface ping error(%v)", err)
  204. c.AbortWithStatus(http.StatusServiceUnavailable)
  205. }
  206. }
  207. func register(c *bm.Context) {
  208. c.JSON(nil, nil)
  209. }