http.go 743 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/passport-encrypt/conf"
  5. "go-common/app/job/main/passport-encrypt/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. engine := bm.DefaultServer(c.BM.Inner)
  15. innerRouter(engine)
  16. if err := engine.Start(); err != nil {
  17. log.Error("bm.DefaultServer error(%v)", err)
  18. panic(err)
  19. }
  20. }
  21. // innerRouter init inner router.
  22. func innerRouter(e *bm.Engine) {
  23. e.Ping(ping)
  24. }
  25. // ping service
  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. }