http.go 744 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/reply-feed/conf"
  5. "go-common/app/job/main/reply-feed/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var (
  10. svc *service.Service
  11. )
  12. // Init init
  13. func Init(c *conf.Config, s *service.Service) {
  14. svc = s
  15. engine := bm.DefaultServer(c.BM)
  16. router(engine)
  17. if err := engine.Start(); err != nil {
  18. log.Error("engine.Start error(%v)", err)
  19. panic(err)
  20. }
  21. }
  22. func router(e *bm.Engine) {
  23. e.Ping(ping)
  24. e.Register(register)
  25. }
  26. func ping(c *bm.Context) {
  27. if err := svc.Ping(c); err != nil {
  28. log.Error("ping error(%v)", err)
  29. c.AbortWithStatus(http.StatusServiceUnavailable)
  30. }
  31. }
  32. func register(c *bm.Context) {
  33. c.JSON(map[string]interface{}{}, nil)
  34. }