rpc.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package server
  2. import (
  3. "go-common/app/interface/main/activity/conf"
  4. matmdl "go-common/app/interface/main/activity/model/like"
  5. match "go-common/app/interface/main/activity/service/like"
  6. "go-common/library/net/rpc"
  7. "go-common/library/net/rpc/context"
  8. "go-common/library/net/rpc/interceptor"
  9. )
  10. // RPC struct info.
  11. type RPC struct {
  12. s *match.Service
  13. }
  14. // New new rpc server.
  15. func New(c *conf.Config, s *match.Service) (svr *rpc.Server) {
  16. r := &RPC{s: s}
  17. svr = rpc.NewServer(c.RPCServer)
  18. in := interceptor.NewInterceptor("")
  19. svr.Interceptor = in
  20. if err := svr.Register(r); err != nil {
  21. panic(err)
  22. }
  23. return
  24. }
  25. // Ping check connection success.
  26. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  27. return
  28. }
  29. // Matchs return matchs by sid
  30. func (r *RPC) Matchs(c context.Context, a *matmdl.ArgMatch, res *[]*matmdl.Match) (err error) {
  31. *res, err = r.s.Match(c, a.Sid)
  32. return
  33. }
  34. // SubjectUp up act_subject cahce info and act_subject maxID cache.
  35. func (r *RPC) SubjectUp(c context.Context, a *matmdl.ArgSubjectUp, res *struct{}) (err error) {
  36. return r.s.SubjectUp(c, a.Sid)
  37. }
  38. // ActSubject get act subject info.
  39. func (r *RPC) ActSubject(c context.Context, a *matmdl.ArgActSubject, res *matmdl.SubjectItem) (err error) {
  40. var rr *matmdl.SubjectItem
  41. if rr, err = r.s.ActSubject(c, a.Sid); err == nil {
  42. *res = *rr
  43. }
  44. return
  45. }
  46. // LikeUp up likes cache info and like maxID cache
  47. func (r *RPC) LikeUp(c context.Context, a *matmdl.ArgLikeUp, res *struct{}) (err error) {
  48. return r.s.LikeUp(c, a.Lid)
  49. }
  50. // AddLikeCtimeCache like ctime cache.
  51. func (r *RPC) AddLikeCtimeCache(c context.Context, a *matmdl.ArgLikeUp, res *struct{}) (err error) {
  52. return r.s.AddLikeCtimeCache(c, a.Lid)
  53. }
  54. // DelLikeCtimeCache del like ctime cache
  55. func (r *RPC) DelLikeCtimeCache(c context.Context, item *matmdl.ArgLikeItem, res *struct{}) (err error) {
  56. return r.s.DelLikeCtimeCache(c, item.ID, item.Sid, item.Type)
  57. }
  58. // ActProtocol .
  59. func (r *RPC) ActProtocol(c context.Context, a *matmdl.ArgActProtocol, res *matmdl.SubProtocol) (err error) {
  60. var rr *matmdl.SubProtocol
  61. if rr, err = r.s.ActProtocol(c, a); err == nil {
  62. *res = *rr
  63. }
  64. return
  65. }