http.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/interface/main/web/conf"
  5. "go-common/app/interface/main/web/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/cache"
  10. "go-common/library/net/http/blademaster/middleware/cache/store"
  11. "go-common/library/net/http/blademaster/middleware/verify"
  12. )
  13. var (
  14. webSvc *service.Service
  15. authSvr *auth.Auth
  16. vfySvr *verify.Verify
  17. // cache components
  18. cacheSvr *cache.Cache
  19. deg *cache.Degrader
  20. )
  21. // Init init
  22. func Init(c *conf.Config, s *service.Service) {
  23. authSvr = auth.New(c.Auth)
  24. vfySvr = verify.New(c.Verify)
  25. webSvc = s
  26. cacheSvr = cache.New(store.NewMemcache(c.DegradeConfig.Memcache))
  27. deg = cache.NewDegrader(c.DegradeConfig.Expire)
  28. // init outer router
  29. engine := bm.NewServer(c.HTTPServer)
  30. engine.Use(bm.Recovery(), bm.Logger(), bm.Trace(), bm.Mobile())
  31. outerRouter(engine)
  32. internalRouter(engine)
  33. if err := engine.Start(); err != nil {
  34. log.Error("engine.Start error(%v)", err)
  35. panic(err)
  36. }
  37. }
  38. func outerRouter(e *bm.Engine) {
  39. e.Ping(ping)
  40. e.GET("/x/web-interface/view", authSvr.Guest, view)
  41. group := e.Group("/x/web-interface", bm.CSRF(), bm.CORS())
  42. {
  43. arcGroup := group.Group("/archive")
  44. {
  45. arcGroup.GET("/coins", authSvr.User, coins)
  46. arcGroup.GET("/stat", archiveStat)
  47. arcGroup.GET("/desc", description)
  48. arcGroup.POST("/report", authSvr.User, arcReport)
  49. arcGroup.POST("/appeal", authSvr.User, arcAppeal)
  50. arcGroup.GET("/appeal/tags", appealTags)
  51. arcGroup.GET("/author/recommend", authorRecommend)
  52. arcGroup.GET("/related", relatedArcs)
  53. arcGroup.POST("/like", authSvr.User, like)
  54. arcGroup.POST("/like/triple", authSvr.User, likeTriple)
  55. arcGroup.GET("/has/like", authSvr.User, hasLike)
  56. arcGroup.GET("/ugc/pay", authSvr.User, arcUGCPay)
  57. arcGroup.GET("/relation", authSvr.User, arcRelation)
  58. }
  59. dyGroup := group.Group("/dynamic")
  60. {
  61. dyGroup.GET("/region", dynamicRegion)
  62. dyGroup.GET("/index", dynamicRegions)
  63. dyGroup.GET("/tag", dynamicRegionTag)
  64. dyGroup.GET("/total", dynamicRegionTotal)
  65. }
  66. rankGroup := group.Group("/ranking")
  67. {
  68. rankGroup.GET("", ranking)
  69. rankGroup.GET("/index", rankingIndex)
  70. rankGroup.GET("/region", rankingRegion)
  71. rankGroup.GET("/recommend", rankingRecommend)
  72. rankGroup.GET("/tag", rankingTag)
  73. }
  74. tagGroup := group.Group("/tag")
  75. {
  76. tagGroup.GET("/top", tagAids)
  77. }
  78. artGroup := group.Group("/article")
  79. {
  80. artGroup.GET("/list", authSvr.Guest, articleList)
  81. artGroup.GET("/up/list", authSvr.Guest, articleUpList)
  82. artGroup.GET("/categories", categories)
  83. artGroup.GET("/newcount", newCount)
  84. artGroup.GET("/early", upMoreArts)
  85. }
  86. coinGroup := group.Group("/coin")
  87. {
  88. coinGroup.POST("/add", authSvr.User, addCoin)
  89. coinGroup.GET("/today/exp", authSvr.User, coinExp)
  90. }
  91. onlineGroup := group.Group("/online")
  92. {
  93. onlineGroup.GET("", onlineInfo)
  94. onlineGroup.GET("/list", onlineList)
  95. }
  96. helpGroup := group.Group("/help")
  97. {
  98. helpGroup.GET("/list", cacheSvr.Cache(deg.Args("parentTypeId"), nil), helpList)
  99. helpGroup.GET("/detail", cacheSvr.Cache(deg.Args("pn", "ps", "fId", "questionTypeId"), nil), helpDetail)
  100. helpGroup.GET("/search", helpSearch)
  101. }
  102. viewGroup := group.Group("/view")
  103. {
  104. viewGroup.GET("/detail", authSvr.Guest, detail)
  105. }
  106. searchGroup := group.Group("/search")
  107. {
  108. searchGroup.GET("/all", authSvr.Guest, searchAll)
  109. searchGroup.GET("/type", authSvr.Guest, searchByType)
  110. searchGroup.GET("/recommend", authSvr.Guest, searchRec)
  111. searchGroup.GET("/default", authSvr.Guest, searchDefault)
  112. searchGroup.GET("/egg", searchEgg)
  113. }
  114. wxGroup := group.Group("/wx")
  115. {
  116. wxGroup.GET("/hot", wxHot)
  117. wxGroup.GET("/search/all", authSvr.Guest, wxSearchAll)
  118. }
  119. bnjGroup := group.Group("/bnj2019")
  120. {
  121. bnjGroup.GET("", authSvr.Guest, bnj2019)
  122. bnjGroup.GET("/timeline", authSvr.Guest, timeline)
  123. }
  124. group.GET("/region/custom", regionCustom)
  125. group.GET("/attentions", authSvr.User, attentions)
  126. group.GET("/card", authSvr.Guest, card)
  127. group.GET("/nav", authSvr.Guest, nav)
  128. group.GET("/newlist", newList)
  129. group.POST("/feedback", authSvr.Guest, feedback)
  130. group.GET("/zone", ipZone)
  131. group.POST("/share/add", authSvr.Guest, addShare)
  132. group.GET("/elec/show", authSvr.Guest, elecShow)
  133. group.GET("/index/icon", indexIcon)
  134. group.GET("/baidu/kv", kv)
  135. group.GET("/cmtbox", cmtbox)
  136. group.GET("/abserver", authSvr.Guest, abServer)
  137. group.GET("/up/rec", authSvr.User, upRec)
  138. group.GET("/broadcast/servers", broadServer)
  139. }
  140. e.GET("/x/coin/list", coinList)
  141. }
  142. func internalRouter(e *bm.Engine) {
  143. group := e.Group("/x/internal/web-interface")
  144. {
  145. dyGroup := group.Group("/dynamic")
  146. {
  147. dyGroup.GET("/region", vfySvr.Verify, dynamicRegion)
  148. dyGroup.GET("/index", vfySvr.Verify, dynamicRegions)
  149. dyGroup.GET("/tag", vfySvr.Verify, dynamicRegionTag)
  150. dyGroup.GET("/total", vfySvr.Verify, dynamicRegionTotal)
  151. }
  152. rankGroup := group.Group("/ranking")
  153. {
  154. rankGroup.GET("", vfySvr.Verify, ranking)
  155. rankGroup.GET("/index", vfySvr.Verify, rankingIndex)
  156. rankGroup.GET("/region", vfySvr.Verify, rankingRegion)
  157. rankGroup.GET("/recommend", vfySvr.Verify, rankingRecommend)
  158. rankGroup.GET("/tag", vfySvr.Verify, rankingTag)
  159. }
  160. tagGroup := group.Group("/tag")
  161. {
  162. tagGroup.GET("/top", vfySvr.Verify, tagAids)
  163. tagGroup.GET("/detail", vfySvr.Verify, tagDetail)
  164. }
  165. helpGroup := group.Group("/help")
  166. {
  167. helpGroup.GET("/list", vfySvr.Verify, helpList)
  168. helpGroup.GET("/detail", vfySvr.Verify, helpDetail)
  169. helpGroup.GET("/search", vfySvr.Verify, helpSearch)
  170. }
  171. onlineGroup := group.Group("/online")
  172. {
  173. onlineGroup.GET("", vfySvr.Verify, onlineInfo)
  174. onlineGroup.GET("/list", vfySvr.Verify, onlineList)
  175. }
  176. viewGroup := group.Group("/view")
  177. {
  178. viewGroup.GET("", vfySvr.Verify, authSvr.Guest, view)
  179. viewGroup.GET("/detail", vfySvr.Verify, authSvr.Guest, detail)
  180. }
  181. searchGroup := group.Group("/search")
  182. {
  183. searchGroup.GET("/all", vfySvr.Verify, authSvr.Guest, searchAll)
  184. searchGroup.GET("/type", vfySvr.Verify, authSvr.Guest, searchByType)
  185. searchGroup.GET("/recommend", vfySvr.Verify, authSvr.Guest, searchRec)
  186. }
  187. group.GET("/newlist", vfySvr.Verify, newList)
  188. group.GET("/zone", vfySvr.Verify, ipZone)
  189. group.GET("/region/custom", vfySvr.Verify, regionCustom)
  190. group.GET("/baidu/kv", vfySvr.Verify, kv)
  191. group.GET("/cmtbox", vfySvr.Verify, cmtbox)
  192. group.GET("/broadcast/servers", vfySvr.Verify, broadServer)
  193. group.GET("/bnj2019", vfySvr.Verify, authSvr.Guest, bnj2019)
  194. group.GET("/bnj2019/aids", vfySvr.Verify, bnj2019Aids)
  195. }
  196. }
  197. func ping(c *bm.Context) {
  198. if err := webSvc.Ping(c); err != nil {
  199. log.Error("web-interface ping error")
  200. c.AbortWithStatus(http.StatusServiceUnavailable)
  201. }
  202. }