http.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/job/main/app-wall/conf"
  5. "go-common/app/job/main/app-wall/service/offer"
  6. "go-common/app/job/main/app-wall/service/unicom"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. var (
  11. offerSvc *offer.Service
  12. unicomSvc *unicom.Service
  13. )
  14. // Init init
  15. func Init(c *conf.Config) {
  16. initService(c)
  17. // init router
  18. engineInner := bm.DefaultServer(c.BM.Inner)
  19. outerRouter(engineInner)
  20. if err := engineInner.Start(); err != nil {
  21. log.Error("bm.DefaultServer error(%v)", err)
  22. panic(err)
  23. }
  24. }
  25. // initService init services.
  26. func initService(c *conf.Config) {
  27. offerSvc = offer.New(c)
  28. unicomSvc = unicom.New(c)
  29. }
  30. // Close
  31. func Close() {
  32. offerSvc.Close()
  33. unicomSvc.Close()
  34. }
  35. // outerRouter init outer router api path.
  36. func outerRouter(e *bm.Engine) {
  37. //init api
  38. e.Ping(ping)
  39. }
  40. // ping check server ok.
  41. func ping(c *bm.Context) {
  42. if err := offerSvc.Ping(c); err != nil {
  43. log.Error("app-wall-job service ping error(%+v)", err)
  44. c.AbortWithStatus(http.StatusServiceUnavailable)
  45. }
  46. }