http.go 756 B

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