http.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package http
  2. import (
  3. "go-common/app/interface/main/app-intl/conf"
  4. "go-common/app/interface/main/app-intl/service/feed"
  5. "go-common/app/interface/main/app-intl/service/player"
  6. "go-common/app/interface/main/app-intl/service/search"
  7. "go-common/app/interface/main/app-intl/service/view"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/http/blademaster/middleware/auth"
  11. "go-common/library/net/http/blademaster/middleware/verify"
  12. )
  13. var (
  14. // depend service
  15. authSvc *auth.Auth
  16. verifySvc *verify.Verify
  17. // self service
  18. feedSvc *feed.Service
  19. viewSvc *view.Service
  20. playerSvc *player.Service
  21. searchSvc *search.Service
  22. )
  23. // Init is
  24. func Init(c *conf.Config) {
  25. initService(c)
  26. // init external router
  27. engineOut := bm.DefaultServer(c.BM.Outer)
  28. outerRouter(engineOut)
  29. // init outer server
  30. if err := engineOut.Start(); err != nil {
  31. log.Error("engineOut.Start() error(%v)", err)
  32. panic(err)
  33. }
  34. }
  35. // initService init services.
  36. func initService(c *conf.Config) {
  37. authSvc = auth.New(nil)
  38. verifySvc = verify.New(nil)
  39. // init self service
  40. feedSvc = feed.New(c)
  41. viewSvc = view.New(c)
  42. playerSvc = player.New(c)
  43. searchSvc = search.New(c)
  44. }
  45. // outerRouter init outer router api path.
  46. func outerRouter(e *bm.Engine) {
  47. e.Ping(ping)
  48. feed := e.Group("/x/intl/feed")
  49. feed.GET("/index", authSvc.GuestMobile, feedIndex)
  50. view := e.Group("/x/intl/view")
  51. view.GET("", verifySvc.Verify, authSvc.GuestMobile, viewIndex)
  52. view.GET("/page", verifySvc.Verify, authSvc.GuestMobile, viewPage)
  53. e.GET("/x/intl/playurl", verifySvc.Verify, authSvc.GuestMobile, playurl)
  54. search := e.Group("/x/intl/search")
  55. search.GET("", authSvc.GuestMobile, searchAll)
  56. search.GET("/type", authSvc.GuestMobile, searchByType)
  57. search.GET("/suggest3", authSvc.GuestMobile, suggest3)
  58. }