http.go 828 B

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