http.go 699 B

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