http.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package http
  2. import (
  3. http2 "net/http"
  4. "go-common/app/admin/main/videoup-task/conf"
  5. "go-common/app/admin/main/videoup-task/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/permit"
  9. "go-common/library/net/http/blademaster/middleware/verify"
  10. )
  11. var (
  12. srv *service.Service
  13. permSrv *permit.Permit
  14. vfySvc *verify.Verify
  15. )
  16. //Init init http
  17. func Init(conf *conf.Config, s *service.Service) {
  18. srv = s
  19. permSrv = permit.New(conf.Auth)
  20. vfySvc = verify.New(nil)
  21. engine := bm.DefaultServer(conf.BM)
  22. innerRoute(engine)
  23. if err := engine.Start(); err != nil {
  24. log.Error("engine.Start error(%v)", err)
  25. panic(err)
  26. }
  27. }
  28. func innerRoute(engine *bm.Engine) {
  29. engine.Ping(ping)
  30. g := engine.Group("/x/admin/vt")
  31. {
  32. v := g.Group("/video", permSrv.Permit("TASK_QA_VIDEO"))
  33. {
  34. v.GET("/list", list)
  35. v.GET("/detail", detail)
  36. v.POST("/submit", submit)
  37. }
  38. t := g.Group("/task", permSrv.Permit(""))
  39. {
  40. w := t.Group("/", permSrv.Permit("TASKWEIGHT"))
  41. {
  42. w.GET("/weightconfig/maxweight", maxweight)
  43. w.POST("/weightconfig/add", addwtconf)
  44. w.POST("/weightconfig/del", delwtconf)
  45. w.GET("/weightconfig/list", listwtconf)
  46. w.GET("/weightlog/list", listwtlog)
  47. w.GET("/wcv/show", show)
  48. w.POST("/wcv/set", set)
  49. }
  50. r := t.Group("/review")
  51. {
  52. r.GET("/config/list", listreviews)
  53. r.POST("/config/add", addreview)
  54. r.POST("/config/edit", editreview)
  55. r.POST("/config/delete", delreview)
  56. }
  57. c := t.Group("consumer")
  58. {
  59. c.GET("/on", checkgroup(), on)
  60. c.GET("/off", checkgroup(), off) //自己退出
  61. c.POST("/forceoff", forceoff) //强制踢出
  62. }
  63. t.GET("/online", permSrv.Permit("ONLINE"), online)
  64. t.GET("/inoutlist", inoutlist)
  65. t.POST("/delay", checkowner(), delay)
  66. t.POST("/free", taskfree)
  67. }
  68. }
  69. g = engine.Group("/vt", vfySvc.Verify)
  70. {
  71. v := g.Group("/video")
  72. {
  73. v.POST("/add", add)
  74. v.POST("/uputime", upTaskUTime)
  75. }
  76. g.GET("/report/memberstats", memberStats)
  77. r := g.Group("review")
  78. {
  79. r.POST("/check", checkReview)
  80. }
  81. t := g.Group("task")
  82. {
  83. t.GET("/tooks", taskTooks)
  84. t.GET("/next", next)
  85. t.GET("/list", listTask)
  86. t.GET("/info", info)
  87. }
  88. }
  89. }
  90. func ping(ctx *bm.Context) {
  91. if srv.Ping(ctx) != nil {
  92. ctx.AbortWithStatus(http2.StatusServiceUnavailable)
  93. ctx.Done()
  94. }
  95. }
  96. func getUIDName(ctx *bm.Context) (uid int64, username string) {
  97. if uidi, _ := ctx.Get("uid"); uidi != nil {
  98. uid = uidi.(int64)
  99. }
  100. if name, _ := ctx.Get("username"); name != nil {
  101. username = name.(string)
  102. }
  103. return
  104. }