http.go 676 B

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