http.go 783 B

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