http.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/main/push/conf"
  5. "go-common/app/service/main/push/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/verify"
  9. )
  10. var (
  11. pushSrv *service.Service
  12. idfSrv *verify.Verify
  13. )
  14. // Init init http.
  15. func Init(c *conf.Config, srv *service.Service) {
  16. idfSrv = verify.New(c.Verify)
  17. pushSrv = srv
  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/internal/push-service", bm.CORS())
  28. {
  29. g.POST("/single", idfSrv.Verify, singlePush)
  30. // for 直播
  31. g.POST("/setting/set", idfSrv.Verify, setSettingInternal)
  32. // for 管理后台测试推送
  33. g.POST("/push", idfSrv.Verify, push)
  34. // for test
  35. g.POST("/test/token", idfSrv.Verify, testToken)
  36. // upload image
  37. g.POST("/upimg", upimg)
  38. }
  39. }
  40. func ping(c *bm.Context) {
  41. if err := pushSrv.Ping(c); err != nil {
  42. log.Error("push-service ping error(%v)", err)
  43. c.AbortWithStatus(http.StatusServiceUnavailable)
  44. }
  45. }