http.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/interface/main/esports/conf"
  5. "go-common/app/interface/main/esports/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/verify"
  10. )
  11. var (
  12. authn *auth.Auth
  13. vfySvr *verify.Verify
  14. eSvc *service.Service
  15. )
  16. // Init init http server
  17. func Init(c *conf.Config, s *service.Service) {
  18. authn = auth.New(c.Auth)
  19. vfySvr = verify.New(c.Verify)
  20. eSvc = s
  21. engine := bm.DefaultServer(c.BM)
  22. outerRouter(engine)
  23. internalRouter(engine)
  24. if err := engine.Start(); err != nil {
  25. log.Error("httpx.Serve error(%v)", err)
  26. panic(err)
  27. }
  28. }
  29. // outerRouter init outer router api path.
  30. func outerRouter(e *bm.Engine) {
  31. e.Ping(ping)
  32. group := e.Group("/x/esports", bm.CORS())
  33. {
  34. group.GET("/season", season)
  35. group.GET("/app/season", appSeason)
  36. matGroup := group.Group("/matchs")
  37. {
  38. matGroup.GET("/filter", filterMatch)
  39. matGroup.GET("/list", authn.Guest, listContest)
  40. matGroup.GET("/app/list", authn.Guest, appContest)
  41. matGroup.GET("/calendar", calendar)
  42. matGroup.GET("/active", authn.Guest, active)
  43. matGroup.GET("/videos", authn.Guest, actVideos)
  44. matGroup.GET("/points", authn.Guest, actPoints)
  45. matGroup.GET("/top", authn.Guest, actTop)
  46. matGroup.GET("/knockout", authn.Guest, actKnockout)
  47. matGroup.GET("/info", authn.Guest, contest)
  48. matGroup.GET("/recent", authn.Guest, recent)
  49. }
  50. videoGroup := group.Group("/video")
  51. {
  52. videoGroup.GET("/filter", filterVideo)
  53. videoGroup.GET("/list", listVideo)
  54. videoGroup.GET("/search", authn.Guest, search)
  55. }
  56. favGroup := group.Group("/fav")
  57. {
  58. favGroup.GET("", authn.Guest, listFav)
  59. favGroup.GET("/season", authn.Guest, seasonFav)
  60. favGroup.GET("/stime", authn.Guest, stimeFav)
  61. favGroup.GET("/list", authn.Guest, appListFav)
  62. favGroup.POST("/add", authn.User, addFav)
  63. favGroup.POST("/del", authn.User, delFav)
  64. }
  65. pointGroup := group.Group("/leida")
  66. {
  67. pointGroup.GET("/game", game)
  68. pointGroup.GET("/items", items)
  69. pointGroup.GET("/heroes", heroes)
  70. pointGroup.GET("/abilities", abilities)
  71. pointGroup.GET("/players", players)
  72. }
  73. }
  74. }
  75. func internalRouter(e *bm.Engine) {
  76. group := e.Group("/x/internal/esports")
  77. {
  78. group.GET("/season", vfySvr.Verify, season)
  79. group.GET("/app/season", vfySvr.Verify, appSeason)
  80. matGroup := group.Group("/matchs")
  81. {
  82. matGroup.GET("/filter", vfySvr.Verify, filterMatch)
  83. matGroup.GET("/list", vfySvr.Verify, listContest)
  84. matGroup.GET("/app/list", vfySvr.Verify, appContest)
  85. matGroup.GET("/calendar", vfySvr.Verify, calendar)
  86. matGroup.GET("/active", vfySvr.Verify, active)
  87. matGroup.GET("/videos", vfySvr.Verify, actVideos)
  88. matGroup.GET("/points", vfySvr.Verify, actPoints)
  89. matGroup.GET("/top", vfySvr.Verify, actTop)
  90. matGroup.GET("/knockout", vfySvr.Verify, actKnockout)
  91. matGroup.GET("/info", vfySvr.Verify, contest)
  92. matGroup.GET("/recent", vfySvr.Verify, recent)
  93. }
  94. videoGroup := group.Group("/video")
  95. {
  96. videoGroup.GET("/filter", vfySvr.Verify, filterVideo)
  97. videoGroup.GET("/list", vfySvr.Verify, listVideo)
  98. videoGroup.GET("/search", vfySvr.Verify, search)
  99. }
  100. favGroup := group.Group("/fav")
  101. {
  102. favGroup.GET("", vfySvr.Verify, listFav)
  103. favGroup.GET("/season", vfySvr.Verify, seasonFav)
  104. favGroup.GET("/stime", vfySvr.Verify, stimeFav)
  105. favGroup.GET("/list", vfySvr.Verify, appListFav)
  106. }
  107. }
  108. }
  109. func ping(c *bm.Context) {
  110. if err := eSvc.Ping(c); err != nil {
  111. log.Error("esports interface ping error")
  112. c.AbortWithStatus(http.StatusServiceUnavailable)
  113. }
  114. }