http.go 841 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/app-player/conf"
  5. "go-common/app/job/main/app-player/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. // is
  10. var (
  11. Svc *service.Service
  12. )
  13. // Init init http
  14. func Init(c *conf.Config) {
  15. initService(c)
  16. // init external router
  17. engineIn := bm.DefaultServer(c.BM)
  18. innerRouter(engineIn)
  19. // init Inner server
  20. if err := engineIn.Start(); err != nil {
  21. log.Error("bm.DefaultServer error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. func initService(c *conf.Config) {
  26. Svc = service.New(c)
  27. }
  28. // innerRouter init inner router api path.
  29. func innerRouter(e *bm.Engine) {
  30. e.Ping(ping)
  31. }
  32. func ping(c *bm.Context) {
  33. err := Svc.Ping(c)
  34. if err != nil {
  35. log.Error("app-player-job service ping error(%+v)", err)
  36. c.AbortWithStatus(http.StatusServiceUnavailable)
  37. }
  38. }