http.go 731 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/passport-user/conf"
  5. "go-common/app/job/main/passport-user/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) {
  14. srv = service.New(c)
  15. engine := bm.DefaultServer(c.BM)
  16. innerRouter(engine)
  17. if err := engine.Start(); err != nil {
  18. log.Error("engine.Start() 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 service
  27. func ping(c *bm.Context) {
  28. if err := srv.Ping(c); err != nil {
  29. log.Error("ping error(%v)", err)
  30. c.AbortWithStatus(http.StatusServiceUnavailable)
  31. }
  32. }