http.go 855 B

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