http.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package http
  2. import (
  3. "go-common/app/interface/main/app-feed/conf"
  4. "go-common/app/interface/main/app-feed/service/external"
  5. "go-common/app/interface/main/app-feed/service/feed"
  6. pingsvc "go-common/app/interface/main/app-feed/service/ping"
  7. "go-common/app/interface/main/app-feed/service/region"
  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. regionSvc *region.Service
  19. feedSvc *feed.Service
  20. pingSvc *pingsvc.Service
  21. externalSvc *external.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. regionSvc = region.New(c)
  41. feedSvc = feed.New(c)
  42. pingSvc = pingsvc.New(c)
  43. externalSvc = external.New(c)
  44. }
  45. // outerRouter init outer router api path.
  46. func outerRouter(e *bm.Engine) {
  47. e.Ping(ping)
  48. // formal api
  49. feed := e.Group("/x/feed")
  50. feed.GET("/region/tags", authSvc.GuestMobile, tags)
  51. feed.GET("/subscribe/tags", authSvc.UserMobile, subTags)
  52. feed.POST("/subscribe/tags/add", authSvc.UserMobile, addTag)
  53. feed.POST("/subscribe/tags/cancel", authSvc.UserMobile, cancelTag)
  54. feed.GET("/index", authSvc.GuestMobile, feedIndex)
  55. feed.GET("/index/tab", authSvc.GuestMobile, feedIndexTab)
  56. feed.GET("/upper", authSvc.UserMobile, feedUpper)
  57. feed.GET("/upper/archive", authSvc.UserMobile, feedUpperArchive)
  58. feed.GET("/upper/bangumi", authSvc.UserMobile, feedUpperBangumi)
  59. feed.GET("/upper/recent", authSvc.UserMobile, feedUpperRecent)
  60. feed.GET("/upper/article", authSvc.UserMobile, feedUpperArticle)
  61. feed.GET("/upper/unread/count", authSvc.UserMobile, feedUnreadCount)
  62. feed.GET("/dislike", authSvc.GuestMobile, feedDislike)
  63. feed.GET("/dislike/cancel", authSvc.GuestMobile, feedDislikeCancel)
  64. feed.POST("/rcmd/up", verifySvc.Verify, upRcmd)
  65. feedV2 := e.Group("/x/v2/feed")
  66. feedV2.GET("/index", authSvc.Guest, feedIndex2)
  67. feedV2.GET("/index/tab", authSvc.Guest, feedIndexTab2)
  68. feedV2.GET("/index/converge", authSvc.Guest, feedIndexConverge)
  69. // live dynamic
  70. external := e.Group("/x/feed/external")
  71. external.GET("/dynamic/count", dynamicCount)
  72. external.GET("/dynamic/new", dynamicNew)
  73. external.GET("/dynamic/history", dynamicHistory)
  74. }