rpc.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package rpc
  2. import (
  3. "go-common/app/service/main/rank/conf"
  4. "go-common/app/service/main/rank/model"
  5. "go-common/app/service/main/rank/service"
  6. "go-common/library/net/rpc"
  7. "go-common/library/net/rpc/context"
  8. )
  9. // RPC favorite rpc.
  10. type RPC struct {
  11. c *conf.Config
  12. s *service.Service
  13. }
  14. // New init rpc.
  15. func New(c *conf.Config, s *service.Service) (svr *rpc.Server) {
  16. r := &RPC{
  17. c: c,
  18. s: s,
  19. }
  20. svr = rpc.NewServer(c.RPCServer)
  21. if err := svr.Register(r); err != nil {
  22. panic(err)
  23. }
  24. return
  25. }
  26. // Ping check connection success.
  27. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  28. return
  29. }
  30. // Mget .
  31. func (r *RPC) Mget(c context.Context, a *model.MgetReq, res *model.MgetResp) (err error) {
  32. var v *model.MgetResp
  33. if v, err = r.s.Mget(c, a); err == nil {
  34. *res = *v
  35. }
  36. return
  37. }
  38. // Sort .
  39. func (r *RPC) Sort(c context.Context, a *model.SortReq, res *model.SortResp) (err error) {
  40. var v *model.SortResp
  41. if v, err = r.s.Sort(c, a); err == nil {
  42. *res = *v
  43. }
  44. return
  45. }
  46. // Group .
  47. func (r *RPC) Group(c context.Context, a *model.GroupReq, res *model.GroupResp) (err error) {
  48. var v *model.GroupResp
  49. if v, err = r.s.Group(c, a); err == nil {
  50. *res = *v
  51. }
  52. return
  53. }