http.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package http
  2. import (
  3. "go-common/app/service/main/resource/conf"
  4. "go-common/app/service/main/resource/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/verify"
  8. )
  9. var (
  10. vfySvc *verify.Verify
  11. resSvc *service.Service
  12. )
  13. // Init int http service
  14. func Init(c *conf.Config, s *service.Service) {
  15. vfySvc = verify.New(c.Verify)
  16. resSvc = s
  17. // init internal router
  18. engineInner := bm.DefaultServer(c.BM.Inner)
  19. innerRouter(engineInner)
  20. // init internal server
  21. if err := engineInner.Start(); err != nil {
  22. log.Error("engineInner.Start() error(%v) | config(%v)", err, c)
  23. panic(err)
  24. }
  25. // init external router
  26. engineLocal := bm.DefaultServer(c.BM.Local)
  27. localRouter(engineLocal)
  28. // init external server
  29. if err := engineLocal.Start(); err != nil {
  30. log.Error("engineLocal.Start() error(%v) | config(%v)", err, c)
  31. panic(err)
  32. }
  33. }
  34. // innerRouter init outer router api path.
  35. func innerRouter(e *bm.Engine) {
  36. e.Ping(ping)
  37. e.Register(register)
  38. rs := e.Group("/x/internal/resource")
  39. bn := rs.Group("/banner")
  40. bn.GET("", banner)
  41. ads := rs.Group("/ads")
  42. ads.GET("/paster/app", vfySvc.Verify, pasterAPP)
  43. ads.GET("/paster/pgc", vfySvc.Verify, pasterPGC)
  44. res := rs.Group("/res")
  45. res.GET("", vfySvc.Verify, resource)
  46. res.GET("/resources", vfySvc.Verify, resources)
  47. res.GET("/indexIcon", vfySvc.Verify, indexIcon)
  48. res.GET("/playerIcon", vfySvc.Verify, playerIcon)
  49. res.GET("/cmtbox", vfySvc.Verify, cmtbox)
  50. res.GET("/regionCard", vfySvc.Verify, regionCard)
  51. res.GET("/audit", vfySvc.Verify, audit)
  52. }
  53. // localRouter init local router api path.
  54. func localRouter(e *bm.Engine) {
  55. e.GET("/x/resource/version", version)
  56. e.GET("/x/resource/monitor", monitor)
  57. }