http.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/relation/conf"
  5. "go-common/app/job/main/relation/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. // // init inner server
  18. // if err := xhttp.Serve(intM, c.MultiHTTP.Inner); err != nil {
  19. // log.Error("xhttp.Serve error(%v)", err)
  20. // panic(err)
  21. // }
  22. innerEngine := bm.DefaultServer(c.BM)
  23. setupInnerEngine(innerEngine)
  24. if err := innerEngine.Start(); err != nil {
  25. panic(err)
  26. }
  27. }
  28. // innerRouter init local router api path.
  29. // func innerRouter(r *router.Router) {
  30. // r.Get("/monitor/ping", 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. }