http.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/main/dynamic/conf"
  5. "go-common/app/service/main/dynamic/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/verify"
  9. )
  10. var (
  11. dySvc *service.Service
  12. vfySvr *verify.Verify
  13. )
  14. // Init init.
  15. func Init(c *conf.Config, s *service.Service) {
  16. vfySvr = verify.New(c.Verify)
  17. dySvc = s
  18. engineInner := bm.DefaultServer(c.HTTPServer)
  19. innerRouter(engineInner)
  20. // init inner serve
  21. if err := engineInner.Start(); err != nil {
  22. log.Error("engineInner.Start error(%v)", err)
  23. panic(err)
  24. }
  25. }
  26. // innerRouter init inner router.
  27. func innerRouter(e *bm.Engine) {
  28. e.Ping(ping)
  29. e.Register(register)
  30. group := e.Group("/x/dynamic", bm.CORS())
  31. {
  32. group.GET("/tag", vfySvr.Verify, regionTagArcs)
  33. group.GET("/region", vfySvr.Verify, regionArcs)
  34. group.GET("/regions", vfySvr.Verify, regionsArcs)
  35. group.GET("/region/total", vfySvr.Verify, regionTotal)
  36. }
  37. }
  38. // ping check server ok.
  39. func ping(c *bm.Context) {
  40. if err := dySvc.Ping(c); err != nil {
  41. log.Error("dynamic service ping error")
  42. c.AbortWithStatus(http.StatusServiceUnavailable)
  43. }
  44. }
  45. func register(c *bm.Context) {
  46. c.JSON(nil, nil)
  47. }