http.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/member/conf"
  5. "go-common/app/job/main/member/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var srv *service.Service
  10. // Init init http service
  11. func Init(c *conf.Config, s *service.Service) {
  12. srv = s
  13. // init inner router
  14. // intM := http.NewServeMux()
  15. // intR := router.New(intM)
  16. // innerRouter(intR)
  17. engine := bm.DefaultServer(c.BM)
  18. setupInnerEngine(engine)
  19. if err := engine.Start(); err != nil {
  20. panic(err)
  21. }
  22. // init inner server
  23. // if err := xhttp.Serve(intM, c.MultiHTTP.Inner); err != nil {
  24. // log.Error("xhttp.Serve error(%v)", err)
  25. // panic(err)
  26. // }
  27. }
  28. // innerRouter init local router api path.
  29. // func innerRouter(r *router.Router) {
  30. // r.MonitorPing(ping)
  31. // }
  32. func setupInnerEngine(e *bm.Engine) {
  33. e.Ping(ping)
  34. e.Register(register)
  35. }
  36. func ping(c *bm.Context) {
  37. if err := srv.Ping(c); err != nil {
  38. log.Error("ping error(%v)", err)
  39. c.AbortWithStatus(http.StatusServiceUnavailable)
  40. }
  41. }
  42. func register(ctx *bm.Context) {
  43. ctx.JSON(nil, nil)
  44. }