http.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/interface/main/space/conf"
  5. "go-common/app/interface/main/space/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/auth"
  9. "go-common/library/net/http/blademaster/middleware/supervisor"
  10. "go-common/library/net/http/blademaster/middleware/verify"
  11. )
  12. var (
  13. authSvr *auth.Auth
  14. spcSvc *service.Service
  15. spvSvc *supervisor.Supervisor
  16. vfySvc *verify.Verify
  17. )
  18. // Init init http server
  19. func Init(c *conf.Config, s *service.Service) {
  20. authSvr = auth.New(c.Auth)
  21. spvSvc = supervisor.New(c.Supervisor)
  22. vfySvc = verify.New(c.Verify)
  23. spcSvc = s
  24. // init http server
  25. engine := bm.DefaultServer(c.HTTPServer)
  26. outerRouter(engine)
  27. internalRouter(engine)
  28. // init Outer serve
  29. if err := engine.Start(); err != nil {
  30. log.Error("engine.Start error(%v)", err)
  31. panic(err)
  32. }
  33. }
  34. func outerRouter(e *bm.Engine) {
  35. e.GET("/monitor/ping", ping)
  36. group := e.Group("/x/space", bm.CORS())
  37. {
  38. chGroup := group.Group("/channel")
  39. {
  40. chGroup.GET("", authSvr.Guest, channel)
  41. chGroup.GET("/index", authSvr.Guest, channelIndex)
  42. chGroup.GET("/list", authSvr.Guest, channelList)
  43. chGroup.POST("/add", spvSvc.ServeHTTP, authSvr.User, addChannel)
  44. chGroup.POST("/del", authSvr.User, delChannel)
  45. chGroup.POST("/edit", spvSvc.ServeHTTP, authSvr.User, editChannel)
  46. }
  47. chvGroup := group.Group("/channel/video")
  48. {
  49. chvGroup.GET("", authSvr.Guest, channelVideo)
  50. chvGroup.POST("/add", authSvr.User, addChannelVideo)
  51. chvGroup.POST("/del", authSvr.User, delChannelVideo)
  52. chvGroup.POST("/sort", authSvr.User, sortChannelVideo)
  53. chvGroup.GET("/check", authSvr.User, checkChannelVideo)
  54. }
  55. riderGroup := group.Group("/rider")
  56. {
  57. riderGroup.GET("/list", authSvr.User, riderList)
  58. riderGroup.POST("/exit", authSvr.User, exitRider)
  59. }
  60. tagGroup := group.Group("/tag")
  61. {
  62. tagGroup.POST("/sub", authSvr.User, tagSub)
  63. tagGroup.POST("/sub/cancel", authSvr.User, tagCancelSub)
  64. tagGroup.GET("/sub/list", authSvr.Guest, tagSubList)
  65. }
  66. bgmGroup := group.Group("/bangumi")
  67. {
  68. bgmGroup.POST("/concern", authSvr.User, bangumiConcern)
  69. bgmGroup.POST("/unconcern", authSvr.User, bangumiUnConcern)
  70. bgmGroup.GET("/concern/list", authSvr.Guest, bangumiList)
  71. }
  72. topGroup := group.Group("/top")
  73. {
  74. topGroup.GET("/arc", authSvr.Guest, topArc)
  75. topGroup.POST("/arc/set", authSvr.User, setTopArc)
  76. topGroup.POST("/arc/cancel", authSvr.User, cancelTopArc)
  77. topGroup.POST("/dynamic/set", authSvr.User, setTopDynamic)
  78. topGroup.POST("/dynamic/cancel", authSvr.User, cancelTopDynamic)
  79. }
  80. mpGroup := group.Group("/masterpiece")
  81. {
  82. mpGroup.GET("", authSvr.Guest, masterpiece)
  83. mpGroup.POST("/add", authSvr.User, addMasterpiece)
  84. mpGroup.POST("/edit", authSvr.User, editMasterpiece)
  85. mpGroup.POST("/cancel", authSvr.User, cancelMasterpiece)
  86. }
  87. noticeGroup := group.Group("/notice")
  88. {
  89. noticeGroup.GET("", notice)
  90. noticeGroup.POST("/set", authSvr.User, setNotice)
  91. }
  92. accGroup := group.Group("/acc")
  93. {
  94. accGroup.GET("/info", authSvr.Guest, accInfo)
  95. accGroup.GET("/tags", accTags)
  96. accGroup.POST("/tags/set", authSvr.User, setAccTags)
  97. accGroup.GET("/relation", authSvr.User, relation)
  98. }
  99. themeGroup := group.Group("theme")
  100. {
  101. themeGroup.GET("/list", authSvr.User, themeList)
  102. themeGroup.POST("/active", authSvr.User, themeActive)
  103. }
  104. appGroup := group.Group("/app")
  105. {
  106. appGroup.GET("/index", authSvr.Guest, appIndex)
  107. appGroup.GET("/dynamic/list", authSvr.Guest, dynamicList)
  108. appGroup.GET("/played/game", authSvr.Guest, appPlayedGame)
  109. appGroup.GET("/top/photo", authSvr.Guest, appTopPhoto)
  110. }
  111. arcGroup := group.Group("/arc")
  112. {
  113. arcGroup.GET("/search", arcSearch)
  114. arcGroup.GET("/list", arcList)
  115. }
  116. group.GET("/setting", settingInfo)
  117. group.GET("/article", article)
  118. group.GET("/navnum", authSvr.Guest, navNum)
  119. group.GET("/upstat", upStat)
  120. group.GET("/shop", authSvr.User, shopInfo)
  121. group.GET("/album/index", albumIndex)
  122. group.GET("/fav/nav", authSvr.Guest, favNav)
  123. group.GET("/fav/arc", authSvr.Guest, favArc)
  124. group.GET("/coin/video", authSvr.Guest, coinVideo)
  125. group.GET("/myinfo", authSvr.User, myInfo)
  126. group.GET("/lastplaygame", authSvr.Guest, lastPlayGame)
  127. group.POST("/privacy/modify", authSvr.User, privacyModify)
  128. group.POST("/index/order/modify", authSvr.User, indexOrderModify)
  129. }
  130. }
  131. func internalRouter(e *bm.Engine) {
  132. group := e.Group("/x/internal/space")
  133. {
  134. group.GET("/setting", vfySvc.Verify, settingInfo)
  135. group.GET("/myinfo", vfySvc.Verify, authSvr.User, myInfo)
  136. group.POST("/privacy/modify", authSvr.User, privacyModify)
  137. group.POST("/privacy/batch/modify", authSvr.User, privacyBatchModify)
  138. group.POST("/index/order/modify", authSvr.User, indexOrderModify)
  139. accGroup := group.Group("/acc")
  140. {
  141. accGroup.GET("/info", vfySvc.Verify, authSvr.Guest, accInfo)
  142. }
  143. appGroup := group.Group("/app")
  144. {
  145. appGroup.GET("/index", vfySvc.Verify, authSvr.Guest, appIndex)
  146. }
  147. group.GET("/web/index", vfySvc.Verify, authSvr.Guest, webIndex)
  148. group.POST("/cache/clear", clearCache)
  149. group.GET("/blacklist", vfySvc.Verify, blacklist)
  150. }
  151. }
  152. func ping(c *bm.Context) {
  153. if err := spcSvc.Ping(c); err != nil {
  154. log.Error("space-interface ping error(%v)", err)
  155. c.AbortWithStatus(http.StatusServiceUnavailable)
  156. }
  157. }