http.go 737 B

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