http.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package http
  2. import (
  3. "go-common/app/interface/main/app-channel/conf"
  4. channelSvr "go-common/app/interface/main/app-channel/service/channel"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/auth"
  8. "go-common/library/net/http/blademaster/middleware/proxy"
  9. "go-common/library/net/http/blademaster/middleware/verify"
  10. )
  11. var (
  12. // depend service
  13. channelSvc *channelSvr.Service
  14. verifySvc *verify.Verify
  15. authSvc *auth.Auth
  16. )
  17. func Init(c *conf.Config) {
  18. initService(c)
  19. // init external router
  20. engineOut := bm.DefaultServer(c.BM.Outer)
  21. outerRouter(engineOut)
  22. // init Outer server
  23. if err := engineOut.Start(); err != nil {
  24. log.Error("engineOut.Start() error(%v) | config(%v)", err, c)
  25. panic(err)
  26. }
  27. }
  28. // initService init services.
  29. func initService(c *conf.Config) {
  30. channelSvc = channelSvr.New(c)
  31. verifySvc = verify.New(nil)
  32. authSvc = auth.New(nil)
  33. }
  34. // outerRouter init outer router api path.
  35. func outerRouter(e *bm.Engine) {
  36. e.Ping(ping)
  37. proxyHandler := proxy.NewZoneProxy("sh004", "http://sh001-app.bilibili.com")
  38. cl := e.Group("/x/channel", verifySvc.Verify)
  39. {
  40. feed := cl.Group("/feed", authSvc.GuestMobile)
  41. {
  42. feed.GET("", index)
  43. feed.GET("/index", proxyHandler, index2)
  44. feed.GET("/tab", tab)
  45. feed.GET("/tab/list", tablist)
  46. }
  47. cl.POST("/add", authSvc.UserMobile, subscribeAdd)
  48. cl.POST("/cancel", authSvc.UserMobile, subscribeCancel)
  49. cl.POST("/update", authSvc.UserMobile, subscribeUpdate)
  50. cl.GET("/list", authSvc.GuestMobile, list)
  51. cl.GET("/subscribe", authSvc.UserMobile, subscribe)
  52. cl.GET("/discover", authSvc.GuestMobile, discover)
  53. cl.GET("/category", authSvc.GuestMobile, category)
  54. cl.GET("/square", authSvc.GuestMobile, square)
  55. cl.GET("/mysub", authSvc.UserMobile, mysub)
  56. }
  57. }