rpc.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package server
  2. import (
  3. "go-common/app/service/main/usersuit/conf"
  4. "go-common/app/service/main/usersuit/model"
  5. "go-common/app/service/main/usersuit/service"
  6. "go-common/library/net/rpc"
  7. "go-common/library/net/rpc/context"
  8. )
  9. // RPC server struct
  10. type RPC struct {
  11. s *service.Service
  12. }
  13. // New new 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 check connection success.
  23. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  24. return
  25. }
  26. // Buy buy invite code
  27. func (r *RPC) Buy(c context.Context, arg *model.ArgBuy, res *[]*model.Invite) (err error) {
  28. *res, err = r.s.BuyInvite(c, arg.Mid, arg.Num, arg.IP)
  29. return
  30. }
  31. // Apply apply invite code
  32. func (r *RPC) Apply(c context.Context, arg *model.ArgApply, res *struct{}) (err error) {
  33. err = r.s.ApplyInvite(c, arg.Mid, arg.Code, arg.Cookie, arg.IP)
  34. return
  35. }
  36. // Stat stat code
  37. func (r *RPC) Stat(c context.Context, arg *model.ArgStat, res *model.InviteStat) (err error) {
  38. var stat *model.InviteStat
  39. if stat, err = r.s.Stat(c, arg.Mid, arg.IP); err == nil && stat != nil {
  40. *res = *stat
  41. }
  42. return
  43. }
  44. // Equip pendant equip.
  45. func (r *RPC) Equip(c context.Context, arg *model.ArgEquip, res *struct{}) (err error) {
  46. err = r.s.EquipPendant(c, arg.Mid, arg.Pid, arg.Status, arg.Source)
  47. return
  48. }
  49. // GrantByMids one pendant give to multiple users.
  50. func (r *RPC) GrantByMids(c context.Context, arg *model.ArgGrantByMids, res *struct{}) (err error) {
  51. err = r.s.BatchGrantPendantByMid(c, arg.Pid, arg.Expire, arg.Mids)
  52. return
  53. }
  54. // GroupPendantMid get group pendant by mid and gid
  55. func (r *RPC) GroupPendantMid(c context.Context, arg *model.ArgGPMID, res *[]*model.GroupPendantList) (err error) {
  56. *res, err = r.s.GroupPendantMid(c, arg)
  57. return
  58. }