http.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/interface/main/player/conf"
  5. "go-common/app/interface/main/player/service"
  6. "go-common/library/log"
  7. "go-common/library/log/infoc"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/http/blademaster/middleware/auth"
  10. "go-common/library/net/http/blademaster/middleware/verify"
  11. )
  12. var (
  13. authSvr *auth.Auth
  14. vfySvr *verify.Verify
  15. playSvr *service.Service
  16. playInfoc *infoc.Infoc
  17. )
  18. // Init init http.
  19. func Init(c *conf.Config) error {
  20. authSvr = auth.New(c.Auth)
  21. vfySvr = verify.New(c.Verify)
  22. playSvr = service.New(c)
  23. engine := bm.DefaultServer(c.BM.Outer)
  24. outerRouter(engine)
  25. internalRouter(engine)
  26. if err := engine.Start(); err != nil {
  27. log.Error("engine.Start error(%v)", err)
  28. return err
  29. }
  30. // init infoc
  31. if c.Infoc2 != nil {
  32. playInfoc = infoc.New(c.Infoc2)
  33. }
  34. return nil
  35. }
  36. func outerRouter(e *bm.Engine) {
  37. e.GET("/monitor/ping", ping)
  38. e.GET("/x/player.so", bm.CORS(), authSvr.Guest, player)
  39. group := e.Group("/x/player", bm.CORS())
  40. {
  41. group.GET("/policy", authSvr.Guest, policy)
  42. group.GET("/carousel.so", carousel)
  43. group.GET("/view", view)
  44. group.GET("/matsuri", matPage)
  45. group.GET("/pagelist", pageList)
  46. group.GET("/videoshot", videoShot)
  47. group.GET("/playurl/token", authSvr.User, playURLToken)
  48. group.GET("/playurl", authSvr.Guest, playurl)
  49. }
  50. }
  51. func internalRouter(e *bm.Engine) {
  52. group := e.Group("/x/internal/player")
  53. {
  54. group.GET("/playurl", vfySvr.Verify, authSvr.Guest, playurl)
  55. }
  56. }
  57. func ping(c *bm.Context) {
  58. if err := playSvr.Ping(c); err != nil {
  59. log.Error("player service ping error(%v)", err)
  60. c.AbortWithStatus(http.StatusServiceUnavailable)
  61. }
  62. }