http.go 832 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/openplatform/open-market/conf"
  5. "go-common/app/job/openplatform/open-market/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var srv *service.Service
  10. // Init init http sever instance.
  11. func Init(c *conf.Config, s *service.Service) {
  12. srv = s
  13. // init external router
  14. engineIn := bm.DefaultServer(c.BM.Inner)
  15. innerRouter(engineIn)
  16. // init Inner server
  17. if err := engineIn.Start(); err != nil {
  18. log.Error("bm.DefaultServer error(%v)", err)
  19. panic(err)
  20. }
  21. }
  22. // innerRouter init inner router.
  23. func innerRouter(e *bm.Engine) {
  24. e.Ping(ping)
  25. }
  26. // ping check server ok.
  27. func ping(c *bm.Context) {
  28. err := srv.Ping(c)
  29. if err != nil {
  30. log.Error("app-job service ping error(%+v)", err)
  31. c.AbortWithStatus(http.StatusServiceUnavailable)
  32. }
  33. }