http.go 839 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/main/feed/conf"
  5. "go-common/app/service/main/feed/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var fSrv *service.Service
  10. // Init init http service
  11. func Init(c *conf.Config, srv *service.Service) {
  12. fSrv = srv
  13. // init outer router
  14. engineOuter := bm.DefaultServer(c.BM)
  15. outerRouter(engineOuter)
  16. if err := engineOuter.Start(); err != nil {
  17. log.Error("bm.DefaultServer error(%v)", err)
  18. panic(err)
  19. }
  20. }
  21. // outerRouter init outer router
  22. func outerRouter(r *bm.Engine) {
  23. r.Ping(ping)
  24. r.Register(register)
  25. }
  26. func ping(c *bm.Context) {
  27. if err := fSrv.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. }