http.go 834 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package http
  2. import (
  3. "go-common/app/service/main/push-strategy/conf"
  4. "go-common/app/service/main/push-strategy/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/verify"
  8. )
  9. var (
  10. idfSrv *verify.Verify
  11. srv *service.Service
  12. )
  13. // Init .
  14. func Init(c *conf.Config, svc *service.Service) {
  15. srv = svc
  16. idfSrv = verify.New(c.Verify)
  17. engine := bm.DefaultServer(c.HTTPServer)
  18. route(engine)
  19. if err := engine.Start(); err != nil {
  20. log.Error("engine.Start() error(%v)", err)
  21. panic(err)
  22. }
  23. }
  24. func route(e *bm.Engine) {
  25. e.Ping(ping)
  26. g := e.Group("/x/internal/push-strategy", idfSrv.Verify)
  27. {
  28. g.POST("/task/add", addTask)
  29. }
  30. }
  31. func ping(ctx *bm.Context) {
  32. if err := srv.Ping(ctx); err != nil {
  33. ctx.Error = err
  34. ctx.AbortWithStatus(503)
  35. }
  36. }