rpc.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package server
  2. import (
  3. artmdl "go-common/app/interface/openplatform/article/model"
  4. "go-common/app/service/main/feed/conf"
  5. feedmdl "go-common/app/service/main/feed/model"
  6. "go-common/app/service/main/feed/service"
  7. "go-common/library/net/rpc"
  8. "go-common/library/net/rpc/context"
  9. )
  10. // RPC struct info
  11. type RPC struct {
  12. s *service.Service
  13. }
  14. // New new rpc server.
  15. func New(c *conf.Config, s *service.Service) (svr *rpc.Server) {
  16. r := &RPC{s: s}
  17. svr = rpc.NewServer(c.RPCServer)
  18. if err := svr.Register(r); err != nil {
  19. panic(err)
  20. }
  21. return
  22. }
  23. // Ping check connection success.
  24. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  25. return
  26. }
  27. // AddArc add archive when archive passed. purge cache.
  28. func (r *RPC) AddArc(c context.Context, arg *feedmdl.ArgArc, res *struct{}) (err error) {
  29. err = r.s.AddArc(c, arg.Mid, arg.Aid, arg.PubDate, arg.RealIP)
  30. return
  31. }
  32. // DelArc delete archive when archive not passed. purge cache.
  33. func (r *RPC) DelArc(c context.Context, arg *feedmdl.ArgAidMid, res *struct{}) (err error) {
  34. err = r.s.DelArc(c, arg.Mid, arg.Aid, arg.RealIP)
  35. return
  36. }
  37. // PurgeFeedCache purge cache when attention/unattention upper
  38. func (r *RPC) PurgeFeedCache(c context.Context, arg *feedmdl.ArgMid, res *struct{}) (err error) {
  39. err = r.s.PurgeFeedCache(c, arg.Mid, arg.RealIP)
  40. return
  41. }
  42. // AppFeed receive ArgMid contains mid and real ip, then return app feed.
  43. func (r *RPC) AppFeed(c context.Context, arg *feedmdl.ArgFeed, res *[]*feedmdl.Feed) (err error) {
  44. *res, err = r.s.Feed(c, true, arg.Mid, arg.Pn, arg.Ps, arg.RealIP)
  45. return
  46. }
  47. // WebFeed receive ArgMid contains mid and real ip, then return app feed.
  48. func (r *RPC) WebFeed(c context.Context, arg *feedmdl.ArgFeed, res *[]*feedmdl.Feed) (err error) {
  49. *res, err = r.s.Feed(c, false, arg.Mid, arg.Pn, arg.Ps, arg.RealIP)
  50. return
  51. }
  52. // Fold receive ArgFold contains mid, then return upper's fold archives.
  53. func (r *RPC) Fold(c context.Context, arg *feedmdl.ArgFold, res *[]*feedmdl.Feed) (err error) {
  54. *res, err = r.s.Fold(c, arg.Mid, arg.Aid, arg.RealIP)
  55. return
  56. }
  57. // AppUnreadCount receive ArgUnreadCount contains mid, then return unread count.
  58. func (r *RPC) AppUnreadCount(c context.Context, arg *feedmdl.ArgUnreadCount, res *int) (err error) {
  59. *res, err = r.s.UnreadCount(c, true, arg.WithoutBangumi, arg.Mid, arg.RealIP)
  60. return
  61. }
  62. // WebUnreadCount receive ArgUnreadCount contains mid, then return unread count.
  63. func (r *RPC) WebUnreadCount(c context.Context, arg *feedmdl.ArgMid, res *int) (err error) {
  64. withoutBangumi := false
  65. *res, err = r.s.UnreadCount(c, false, withoutBangumi, arg.Mid, arg.RealIP)
  66. return
  67. }
  68. // ArchiveFeed receive ArgFeed contains mid and real ip
  69. func (r *RPC) ArchiveFeed(c context.Context, arg *feedmdl.ArgFeed, res *[]*feedmdl.Feed) (err error) {
  70. *res, err = r.s.ArchiveFeed(c, arg.Mid, arg.Pn, arg.Ps, arg.RealIP)
  71. return
  72. }
  73. // BangumiFeed receive ArgFeed contains mid and real ip
  74. func (r *RPC) BangumiFeed(c context.Context, arg *feedmdl.ArgFeed, res *[]*feedmdl.Feed) (err error) {
  75. *res, err = r.s.BangumiFeed(c, arg.Mid, arg.Pn, arg.Ps, arg.RealIP)
  76. return
  77. }
  78. // ChangeArcUpper refresh feed cache when change archive's author
  79. func (r *RPC) ChangeArcUpper(c context.Context, arg *feedmdl.ArgChangeUpper, res *struct{}) (err error) {
  80. err = r.s.ChangeAuthor(c, arg.Aid, arg.OldMid, arg.NewMid, arg.RealIP)
  81. return
  82. }
  83. // ArticleFeed receive ArgFeed contains mid and real ip
  84. func (r *RPC) ArticleFeed(c context.Context, arg *feedmdl.ArgFeed, res *[]*artmdl.Meta) (err error) {
  85. *res, err = r.s.ArticleFeed(c, arg.Mid, arg.Pn, arg.Ps, arg.RealIP)
  86. return
  87. }
  88. // ArticleUnreadCount receive ArgUnreadCount contains mid, then return unread count.
  89. func (r *RPC) ArticleUnreadCount(c context.Context, arg *feedmdl.ArgMid, res *int) (err error) {
  90. *res, err = r.s.ArticleUnreadCount(c, arg.Mid, arg.RealIP)
  91. return
  92. }