http.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/interface/main/push/conf"
  5. "go-common/app/interface/main/push/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/auth"
  9. )
  10. var (
  11. pushSrv *service.Service
  12. authSrv *auth.Auth
  13. )
  14. // Init init http.
  15. func Init(c *conf.Config, srv *service.Service) {
  16. pushSrv = srv
  17. authSrv = auth.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/push", bm.CORS())
  28. {
  29. // for APP client
  30. g.POST("/report", authSrv.GuestMobile, report)
  31. g.GET("/report_old", reportOld)
  32. g.POST("/setting/set", authSrv.UserMobile, setSetting)
  33. g.GET("/setting/get", authSrv.UserMobile, setting)
  34. // for test
  35. g.POST("/test/token", testToken)
  36. // for callback
  37. cg := g.Group("/callback")
  38. {
  39. cg.POST("/huawei", huaweiCallback) // 华为送达回执
  40. cg.POST("/xiaomi", miCallback) // 小米送达回执
  41. cg.POST("/xiaomi/regid", miRegidCallback) // 小米token注册回执
  42. cg.POST("/oppo", oppoCallback) // oppo送达回执
  43. cg.POST("/jpush", jpushCallback) // 极光送达回执
  44. cg.POST("/ios", iOSCallback) // iOS送达回执
  45. cg.POST("/android", androidCallback) // Android送达回执
  46. cg.POST("/click", clickCallback) // 所有平台的点击回执
  47. }
  48. }
  49. }
  50. func ping(c *bm.Context) {
  51. if err := pushSrv.Ping(c); err != nil {
  52. log.Error("push-interface ping error(%v)", err)
  53. c.AbortWithStatus(http.StatusServiceUnavailable)
  54. }
  55. }