http.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package http
  2. import (
  3. "go-common/app/service/main/archive/conf"
  4. "go-common/app/service/main/archive/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. idfSvc *verify.Verify
  11. arcSvc *service.Service
  12. )
  13. // Init init http router.
  14. func Init(c *conf.Config, s *service.Service) {
  15. arcSvc = s
  16. idfSvc = verify.New(nil)
  17. // init internal router
  18. en := bm.DefaultServer(c.BM.Inner)
  19. innerRouter(en)
  20. // init internal server
  21. if err := en.Start(); err != nil {
  22. log.Error("xhttp.Serve error(%v)", err)
  23. panic(err)
  24. }
  25. // init external router
  26. enlocal := bm.DefaultServer(c.BM.Local)
  27. localRouter(enlocal)
  28. // init external server
  29. if err := enlocal.Start(); err != nil {
  30. log.Error("xhttp.Serve error(%v)", err)
  31. panic(err)
  32. }
  33. }
  34. // innerRouter init inner router.
  35. func innerRouter(e *bm.Engine) {
  36. e.Ping(ping)
  37. e.Register(register)
  38. archive := e.Group("/x/internal/v2/archive", bm.CORS())
  39. {
  40. archive.GET("", idfSvc.Verify, arcInfo)
  41. archive.GET("/view", idfSvc.Verify, arcView)
  42. archive.GET("/views", idfSvc.Verify, arcViews)
  43. archive.GET("/page", idfSvc.Verify, arcPage)
  44. archive.GET("/video", idfSvc.Verify, video)
  45. archive.GET("/archives", idfSvc.Verify, archives)
  46. archive.GET("/archives/playurl", idfSvc.Verify, archivesWithPlayer)
  47. archive.GET("/typelist", idfSvc.Verify, typelist)
  48. archive.GET("/description", idfSvc.Verify, description)
  49. archive.GET("/maxAid", idfSvc.Verify, maxAID)
  50. regionGp := archive.Group("/region")
  51. {
  52. regionGp.GET("", idfSvc.Verify, regionArcs)
  53. }
  54. videoshotGp := archive.Group("/videoshot")
  55. {
  56. videoshotGp.GET("", idfSvc.Verify, videoshot)
  57. }
  58. statGp := archive.Group("/stat")
  59. {
  60. statGp.GET("", idfSvc.Verify, arcStat)
  61. statGp.GET("/stats", idfSvc.Verify, arcStats)
  62. }
  63. upGp := archive.Group("/up")
  64. {
  65. upGp.GET("/count/batch", idfSvc.Verify, uppersCount)
  66. upGp.GET("/count", idfSvc.Verify, upperCount)
  67. upGp.GET("/passed", idfSvc.Verify, upperPassed)
  68. upGp.GET("/cache", idfSvc.Verify, upperCache)
  69. }
  70. }
  71. }
  72. // localRouter init local router.
  73. func localRouter(e *bm.Engine) {
  74. e.GET("/archive-service/rank/init", addRegionArc)
  75. }