rpc.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package server
  2. import (
  3. "go-common/app/service/main/thumbup/conf"
  4. "go-common/app/service/main/thumbup/model"
  5. "go-common/app/service/main/thumbup/service"
  6. "go-common/library/net/rpc"
  7. "go-common/library/net/rpc/context"
  8. )
  9. // RPC .
  10. type RPC struct {
  11. s *service.Service
  12. }
  13. // New creates rpc server.
  14. func New(c *conf.Config, s *service.Service) (svr *rpc.Server) {
  15. r := &RPC{s: s}
  16. svr = rpc.NewServer(c.RPCServer)
  17. if err := svr.Register(r); err != nil {
  18. panic(err)
  19. }
  20. return
  21. }
  22. // Ping checks connection success.
  23. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  24. return
  25. }
  26. // Auth check connection success.
  27. func (r *RPC) Auth(c context.Context, arg *rpc.Auth, res *struct{}) (err error) {
  28. return
  29. }
  30. // Like add like/dislike
  31. func (r *RPC) Like(c context.Context, arg *model.ArgLike, res *struct{}) (err error) {
  32. _, err = r.s.Like(c, arg.Business, arg.Mid, arg.OriginID, arg.MessageID, arg.Type, arg.UpMid)
  33. return
  34. }
  35. // LikeWithStats add like/dislike and return the stats info
  36. func (r *RPC) LikeWithStats(ctx context.Context, arg *model.ArgLike, res *model.Stats) (err error) {
  37. *res, err = r.s.Like(ctx, arg.Business, arg.Mid, arg.OriginID, arg.MessageID, arg.Type, arg.UpMid)
  38. return
  39. }
  40. // Stats return stats message
  41. func (r *RPC) Stats(c context.Context, arg *model.ArgStats, res *map[int64]*model.Stats) (err error) {
  42. *res, err = r.s.Stats(c, arg.Business, arg.OriginID, arg.MessageIDs)
  43. return
  44. }
  45. // UserLikes user likes list
  46. func (r *RPC) UserLikes(c context.Context, arg *model.ArgUserLikes, res *[]*model.ItemLikeRecord) (err error) {
  47. *res, err = r.s.UserLikes(c, arg.Business, arg.Mid, arg.Pn, arg.Ps)
  48. return
  49. }
  50. // UserDislikes user dislikes list
  51. func (r *RPC) UserDislikes(c context.Context, arg *model.ArgUserLikes, res *[]*model.ItemLikeRecord) (err error) {
  52. *res, err = r.s.UserDislikes(c, arg.Business, arg.Mid, arg.Pn, arg.Ps)
  53. return
  54. }
  55. // ItemLikes item likes list
  56. func (r *RPC) ItemLikes(c context.Context, arg *model.ArgItemLikes, res *[]*model.UserLikeRecord) (err error) {
  57. *res, err = r.s.ItemLikes(c, arg.Business, arg.OriginID, arg.MessageID, arg.Pn, arg.Ps, arg.Mid)
  58. return
  59. }
  60. // ItemDislikes item dislikes list
  61. func (r *RPC) ItemDislikes(c context.Context, arg *model.ArgItemLikes, res *[]*model.UserLikeRecord) (err error) {
  62. *res, err = r.s.ItemDislikes(c, arg.Business, arg.OriginID, arg.MessageID, arg.Pn, arg.Ps, arg.Mid)
  63. return
  64. }
  65. // HasLike query user has liked something
  66. func (r *RPC) HasLike(c context.Context, arg *model.ArgHasLike, res *map[int64]int8) (err error) {
  67. *res, _, err = r.s.HasLike(c, arg.Business, arg.Mid, arg.MessageIDs)
  68. return
  69. }
  70. // StatsWithLike return stats and like state
  71. func (r *RPC) StatsWithLike(c context.Context, arg *model.ArgStatsWithLike, res *map[int64]*model.StatsWithLike) (err error) {
  72. *res, err = r.s.StatsWithLike(c, arg.Business, arg.Mid, arg.OriginID, arg.MessageIDs)
  73. return
  74. }
  75. // UserTotalLike user item list with total count
  76. func (r *RPC) UserTotalLike(c context.Context, arg *model.ArgUserLikes, res **model.UserTotalLike) (err error) {
  77. *res, err = r.s.UserTotalLike(c, arg.Business, arg.Mid, arg.Pn, arg.Ps)
  78. return
  79. }
  80. // UpdateCount update count
  81. func (r *RPC) UpdateCount(c context.Context, arg *model.ArgUpdateCount, res *struct{}) (err error) {
  82. err = r.s.UpdateCount(c, arg.Business, arg.OriginID, arg.MessageID, arg.LikeChange, arg.DislikeChange, arg.RealIP, arg.Operator)
  83. return
  84. }
  85. // RawStats get stat changes
  86. func (r *RPC) RawStats(c context.Context, arg *model.ArgRawStats, res *model.RawStats) (err error) {
  87. *res, err = r.s.RawStats(c, arg.Business, arg.OriginID, arg.MessageID)
  88. return
  89. }