http.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/esports/conf"
  5. "go-common/app/admin/main/esports/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/permit"
  9. )
  10. var (
  11. esSvc *service.Service
  12. //idfSvc *identify.Identify
  13. permitSvc *permit.Permit
  14. )
  15. // Init init http sever instance.
  16. func Init(c *conf.Config, s *service.Service) {
  17. esSvc = s
  18. permitSvc = permit.New(c.Permit)
  19. engine := bm.DefaultServer(c.BM)
  20. authRouter(engine)
  21. // init internal server
  22. if err := engine.Start(); err != nil {
  23. log.Error("engine.Start error(%v)", err)
  24. panic(err)
  25. }
  26. }
  27. func authRouter(e *bm.Engine) {
  28. e.Ping(ping)
  29. group := e.Group("/x/admin/esports", permitSvc.Permit("ESPORTS_ADMIN"))
  30. {
  31. matchGroup := group.Group("/matchs")
  32. {
  33. matchGroup.GET("/info", matchInfo)
  34. matchGroup.GET("/list", matchList)
  35. matchGroup.POST("/add", addMatch)
  36. matchGroup.POST("/save", editMatch)
  37. matchGroup.POST("/forbid", forbidMatch)
  38. }
  39. seasonGroup := group.Group("/seasons")
  40. {
  41. seasonGroup.GET("/info", seasonInfo)
  42. seasonGroup.GET("/list", seasonList)
  43. seasonGroup.POST("/add", addSeason)
  44. seasonGroup.POST("/save", editSeason)
  45. seasonGroup.POST("/forbid", forbidSeason)
  46. }
  47. contestGroup := group.Group("/contest")
  48. {
  49. contestGroup.GET("/info", contestInfo)
  50. contestGroup.GET("/list", contestList)
  51. contestGroup.POST("/add", addContest)
  52. contestGroup.POST("/save", editContest)
  53. contestGroup.POST("/forbid", forbidContest)
  54. }
  55. gameGroup := group.Group("/games")
  56. {
  57. gameGroup.GET("/info", gameInfo)
  58. gameGroup.GET("/list", gameList)
  59. gameGroup.POST("/add", addGame)
  60. gameGroup.POST("/save", editGame)
  61. gameGroup.POST("/forbid", forbidGame)
  62. gameGroup.GET("/types", types)
  63. }
  64. teamGroup := group.Group("/teams")
  65. {
  66. teamGroup.GET("/info", teamInfo)
  67. teamGroup.GET("/list", teamList)
  68. teamGroup.POST("/add", addTeam)
  69. teamGroup.POST("/save", editTeam)
  70. teamGroup.POST("/forbid", forbidTeam)
  71. }
  72. tagGroup := group.Group("/tags")
  73. {
  74. tagGroup.GET("/info", tagInfo)
  75. tagGroup.GET("/list", tagList)
  76. tagGroup.POST("/add", addTag)
  77. tagGroup.POST("/save", editTag)
  78. tagGroup.POST("/forbid", forbidTag)
  79. }
  80. arcGroup := group.Group("/arcs")
  81. {
  82. arcGroup.GET("/list", arcList)
  83. arcGroup.POST("/edit", editArc)
  84. arcGroup.POST("/batch/add", batchAddArc)
  85. arcGroup.POST("/batch/edit", batchEditArc)
  86. arcGroup.POST("/batch/del", batchDelArc)
  87. arcGroup.POST("/import/csv", arcImportCSV)
  88. }
  89. actGroup := group.Group("/active")
  90. {
  91. actGroup.GET("", listAct)
  92. actGroup.POST("/add", addAct)
  93. actGroup.POST("/edit", editAct)
  94. actGroup.POST("/forbid", forbidAct)
  95. dGroup := actGroup.Group("/detail")
  96. {
  97. dGroup.GET("/list", listDetail)
  98. dGroup.POST("/add", addDetail)
  99. dGroup.POST("/edit", editDetail)
  100. dGroup.POST("/forbid", forbidDetail)
  101. dGroup.POST("/online", onLine)
  102. }
  103. tGroup := actGroup.Group("/tree")
  104. {
  105. tGroup.GET("/list", listTree)
  106. tGroup.POST("/add", addTree)
  107. tGroup.POST("/edit", editTree)
  108. tGroup.POST("/del", delTree)
  109. }
  110. }
  111. }
  112. }
  113. func ping(c *bm.Context) {
  114. if err := esSvc.Ping(c); err != nil {
  115. log.Error("esport-admin ping error")
  116. c.AbortWithStatus(http.StatusServiceUnavailable)
  117. }
  118. }