http.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/service/video/stream-mng/conf"
  5. "go-common/app/service/video/stream-mng/middleware"
  6. "go-common/app/service/video/stream-mng/service"
  7. "go-common/library/log"
  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. srv *service.Service
  14. vfy *verify.Verify
  15. authSvr *auth.Auth
  16. )
  17. // Init init
  18. func Init(c *conf.Config, svc *service.Service) {
  19. srv = svc
  20. vfy = verify.New(c.Verify)
  21. authSvr = auth.New(c.Auth)
  22. engine := bm.DefaultServer(c.BM)
  23. engine.Use(middleware.Logger())
  24. route(engine)
  25. if err := engine.Start(); err != nil {
  26. log.Error("bm Start error(%v)", err)
  27. panic(err)
  28. }
  29. }
  30. func route(e *bm.Engine) {
  31. e.Ping(ping)
  32. e.Register(register)
  33. g := e.Group("/video/stream-mng")
  34. {
  35. g.GET("/", alive)
  36. g.POST("/stream/backup", createBackupStream)
  37. g.POST("/stream/offical", createOfficalStream)
  38. g.POST("/stream/validate", streamValidate)
  39. g.GET("/stream/old/getbyroomid", getOldStreamInfoByRoomID)
  40. g.GET("/stream/old/getbyname", getOldStreamInfoByStreamName)
  41. g.GET("/notifymaskbyroomid", saveMaskByRoomID) //控制一个主流是否需要转蒙版直播流
  42. g.GET("/notifymaskbystreamname", saveMaskByStreamName) //控制一个主流是否可提供蒙版给PLAYURL
  43. g.POST("/addhotstream", addHotStream) //增加热流到redis
  44. g.GET("/getstream", getStream)
  45. g.GET("/getmultistreams", getMultiStreams)
  46. g.GET("/stream/getRoomIdByStreamName", getRoomIDByStreamName)
  47. g.GET("/stream/getStreamNameByRoomId", getStreamNameByRoomID)
  48. g.POST("/stream/changeSrc", changeSrc)
  49. g.GET("/stream/cut", cutStream)
  50. g.GET("/stream/cutmobilestream", authSvr.User, cutStreamByMobile)
  51. g.GET("/stream/getLastTime", getStreamLastTime)
  52. g.GET("/stream/getAdapterStream", getAdapterStreamByStreamName)
  53. g.GET("/stream/getSrcByRoomID", getSrcByRoomID)
  54. g.GET("/stream/getLineListByRoomID", getLineListByRoomID)
  55. g.GET("/shot/getSinglePic", getSingleScreenShot)
  56. g.GET("/shot/getMultiPic", getMultiScreenShot)
  57. g.GET("/shot/getOriginPic", getOriginScreenShotPic)
  58. g.GET("/shot/getperiodpic", getTimePeriodScreenShot)
  59. g.POST("/stream/clearstreamstatus", clearStreamStatus)
  60. g.GET("/stream/getRoomRtmp", getRoomRtmp) // 拜年祭推流码
  61. g.GET("/stream/getUpStreamRtmp", getUpStreamRtmp) // 后台调用,无需鉴权
  62. g.GET("/stream/getmobilertmp", authSvr.User, getMobileRtmp) // 移动端调用
  63. g.GET("/stream/getwebrtmp", authSvr.User, getWebRtmp) // 被web端和pc_link调用
  64. g.GET("/stream/live", checkLiveStreamList)
  65. // 删除room_id缓存的接口,防止缓存问题出现的bug
  66. g.GET("/stream/clearcache", clearRoomCacheByRID)
  67. // 查询更改记录
  68. g.GET("/change/getchangeLog", getChangeLogByRoomID)
  69. // 查询统计上行调度信息
  70. g.GET("/summary/upstream", getSummaryUpStreamRtmp)
  71. g.GET("/summary/isp", getSummaryUpStreamISP)
  72. g.GET("/summary/country", getSummaryUpStreamCountry)
  73. g.GET("/summary/platform", getSummaryUpStreamPlatform)
  74. g.GET("/summary/city", getSummaryUpStreamCity)
  75. }
  76. g2 := e.Group("/live_stream/v1/StreamThird")
  77. {
  78. g2.POST("/stream_validate", streamValidate)
  79. g2.POST("/open_notify", openNotify)
  80. g2.POST("/close_notify", closeNotify)
  81. }
  82. g7 := e.Group("/live_stream/v1/StreamList")
  83. {
  84. g7.GET("/get_stream_by_roomId", authSvr.User, getWebRtmp)
  85. }
  86. g8 := e.Group("/live_stream/v1/UpStreamExt")
  87. {
  88. g8.GET("/get_by_room", authSvr.User, getMobileRtmp)
  89. g8.GET("/pause_by_room", authSvr.User, cutStreamByMobile)
  90. }
  91. }
  92. func ping(c *bm.Context) {
  93. if err := srv.Ping(c); err != nil {
  94. log.Error("ping error(%v)", err)
  95. c.AbortWithStatus(http.StatusServiceUnavailable)
  96. }
  97. }
  98. func register(c *bm.Context) {
  99. c.JSON(map[string]interface{}{}, nil)
  100. }
  101. func alive(c *bm.Context) {
  102. c.String(0, "Golang 大法好 !!!")
  103. }