http.go 748 B

123456789101112131415161718192021222324252627282930313233343536
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/reply/conf"
  5. "go-common/app/job/main/reply/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var rpSvc *service.Service
  10. // Init init http
  11. func Init(c *conf.Config, svc *service.Service) {
  12. rpSvc = svc
  13. engine := bm.DefaultServer(c.BM)
  14. outerRouter(engine)
  15. if err := engine.Start(); err != nil {
  16. log.Error("bm.DefaultServer error(%v)", err)
  17. panic(err)
  18. }
  19. }
  20. // outerRouter init outer router api path.
  21. func outerRouter(e *bm.Engine) {
  22. e.GET("/monitor/ping", ping)
  23. }
  24. // ping check server ok.
  25. func ping(c *bm.Context) {
  26. if err := rpSvc.Ping(c); err != nil {
  27. log.Error("reply job ping error")
  28. c.AbortWithStatus(http.StatusServiceUnavailable)
  29. }
  30. }