http.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/push/conf"
  5. "go-common/app/admin/main/push/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. pushSrv *service.Service
  12. authSrv *permit.Permit
  13. )
  14. // Init init http sever instance.
  15. func Init(c *conf.Config, s *service.Service) {
  16. pushSrv = s
  17. authSrv = permit.New(c.Auth)
  18. engine := bm.DefaultServer(c.HTTPServer)
  19. route(engine)
  20. if err := engine.Start(); err != nil {
  21. log.Error("engine.Start error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. func route(e *bm.Engine) {
  26. e.Ping(ping)
  27. g := e.Group("/x/admin/push")
  28. {
  29. gapp := g.Group("/apps")
  30. {
  31. gapp.GET("/list", authSrv.Permit("PUSH_APPS_LIST"), appList)
  32. gapp.GET("/info", authSrv.Permit("PUSH_APPS"), appInfo)
  33. gapp.POST("/add", authSrv.Permit("PUSH_APPS"), addApp)
  34. gapp.POST("/save", authSrv.Permit("PUSH_APPS"), saveApp)
  35. gapp.POST("/delete", authSrv.Permit("PUSH_APPS"), delApp)
  36. }
  37. gauth := g.Group("/auths", authSrv.Permit("PUSH_AUTH"))
  38. {
  39. gauth.GET("/list", authList)
  40. gauth.GET("/info", authInfo)
  41. gauth.POST("/add", addAuth)
  42. gauth.POST("/save", saveAuth)
  43. gauth.POST("/delete", delAuth)
  44. }
  45. gbiz := g.Group("/business")
  46. {
  47. gbiz.GET("/list", authSrv.Permit("PUSH_BUSINESS_LIST"), businessList)
  48. gbiz.GET("/info", authSrv.Permit("PUSH_BUSINESS"), businessInfo)
  49. gbiz.POST("/add", authSrv.Permit("PUSH_BUSINESS"), addBusiness)
  50. gbiz.POST("/save", authSrv.Permit("PUSH_BUSINESS"), saveBusiness)
  51. gbiz.POST("/delete", authSrv.Permit("PUSH_BUSINESS"), delBusiness)
  52. }
  53. gtask := g.Group("/tasks")
  54. {
  55. gtask.GET("/list", authSrv.Permit("PUSH_TASK"), taskList)
  56. gtask.GET("/info", authSrv.Permit("PUSH_TASK"), taskInfo)
  57. gtask.POST("/add", authSrv.Permit("PUSH_TASK"), addTask)
  58. gtask.POST("/save", authSrv.Permit("PUSH_TASK"), saveTask)
  59. gtask.POST("/delete", authSrv.Permit("PUSH_TASK"), delTask)
  60. gtask.POST("/upload", authSrv.Permit("PUSH_TASK"), upload)
  61. gtask.POST("/upimg", authSrv.Permit("PUSH_TASK"), upimg)
  62. gtask.POST("/stop", authSrv.Permit("PUSH_TASK"), stopTask)
  63. gtask.POST("/confirm", authSrv.Permit("PUSH_CONFIRM"), confirmTask)
  64. gdp := gtask.Group("dataplatform", authSrv.Permit("PUSH_TASK"))
  65. {
  66. gdp.POST("/add", addDPTask)
  67. gdp.GET("/info", dpTaskInfo)
  68. gdp.GET("/check", checkDpData)
  69. }
  70. }
  71. gtest := g.Group("/test", authSrv.Permit("PUSH_TEST"))
  72. {
  73. gtest.POST("/mid", testPushMid) // 按 mids 测试推送
  74. gtest.POST("/token", testPushToken) // 按单个 token 测试推送
  75. }
  76. }
  77. }
  78. func ping(ctx *bm.Context) {
  79. if err := pushSrv.Ping(ctx); err != nil {
  80. log.Error("push-admin ping error(%v)", err)
  81. ctx.AbortWithStatus(http.StatusServiceUnavailable)
  82. }
  83. }