http.go 693 B

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