http.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/interface/video/portal/conf"
  5. "go-common/app/interface/video/portal/middleware"
  6. "go-common/app/interface/video/portal/service"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/http/blademaster/middleware/verify"
  10. )
  11. var (
  12. srv *service.Service
  13. vfy *verify.Verify
  14. )
  15. // Init init
  16. func Init(c *conf.Config, svc *service.Service) {
  17. srv = svc
  18. vfy = verify.New(c.Verify)
  19. engine := bm.DefaultServer(c.BM)
  20. route(engine)
  21. if err := engine.Start(); err != nil {
  22. log.Error("bm Start error(%v)", err)
  23. panic(err)
  24. }
  25. }
  26. func route(e *bm.Engine) {
  27. e.Ping(ping)
  28. e.Register(register)
  29. g := e.Group("/video/portal")
  30. {
  31. g.GET("/", howToStart)
  32. g.GET("/whitelist", middleware.TXCheckSecretkey, txStreamForwardingConf)
  33. g.GET("/whitelist/conf", middleware.BvcCheckSecret, bvcStreamForwardingConf)
  34. g.GET("/leveltwosourcestation", streamLevelTwoSourceStation)
  35. g.GET("/lplallstar", streamLplAllStar)
  36. }
  37. }
  38. func ping(c *bm.Context) {
  39. if err := srv.Ping(c); err != nil {
  40. log.Error("ping error(%v)", err)
  41. c.AbortWithStatus(http.StatusServiceUnavailable)
  42. }
  43. }
  44. func register(c *bm.Context) {
  45. c.JSON(map[string]interface{}{}, nil)
  46. }
  47. // example for http request handler
  48. func howToStart(c *bm.Context) {
  49. //c.String(0, "Golang 大法好 !!!")
  50. c.JSON(nil, nil)
  51. }