http.go 702 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package http
  2. import (
  3. "go-common/app/job/main/workflow/conf"
  4. "go-common/app/job/main/workflow/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. var (
  9. svr *service.Service
  10. )
  11. func Init(c *conf.Config, s *service.Service) {
  12. svr = s
  13. // init local router
  14. engine := bm.DefaultServer(c.HTTPServer)
  15. route(engine)
  16. // init local server
  17. if err := engine.Start(); err != nil {
  18. log.Error("bm.DefaultServer error(%v)", err)
  19. panic(err)
  20. }
  21. }
  22. // route .
  23. func route(e *bm.Engine) {
  24. e.Ping(ping)
  25. }
  26. // ping check server ok.
  27. func ping(ctx *bm.Context) {
  28. if err := svr.Ping(ctx); err != nil {
  29. log.Error("workflow job ping error(%v)", err)
  30. ctx.AbortWithStatus(503)
  31. }
  32. }