rpc.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package gorpc
  2. import (
  3. "go-common/app/service/main/member/conf"
  4. "go-common/app/service/main/member/model"
  5. "go-common/app/service/main/member/service"
  6. "go-common/app/service/main/member/service/block"
  7. "go-common/library/net/rpc"
  8. "go-common/library/net/rpc/context"
  9. )
  10. // RPC is.
  11. type RPC struct {
  12. s *service.Service
  13. block *block.Service
  14. }
  15. // New new rpc server.
  16. func New(c *conf.Config, s *service.Service) *rpc.Server {
  17. r := &RPC{
  18. s: s,
  19. block: s.BlockImpl(),
  20. }
  21. svr := rpc.NewServer(c.RPCServer)
  22. if err := svr.Register(r); err != nil {
  23. panic(err)
  24. }
  25. return svr
  26. }
  27. // Ping check connection success.
  28. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  29. return
  30. }
  31. // --- exp --- //
  32. // Exp get user exp.
  33. func (r *RPC) Exp(c context.Context, arg *model.ArgMid2, res *model.LevelInfo) (err error) {
  34. v, err := r.s.Exp(c, arg.Mid)
  35. if err == nil && v != nil {
  36. *res = *v
  37. }
  38. return
  39. }
  40. // Level get user exp.
  41. func (r *RPC) Level(c context.Context, arg *model.ArgMid2, res *model.LevelInfo) (err error) {
  42. v, err := r.s.Level(c, arg.Mid)
  43. if err == nil && v != nil {
  44. *res = *v
  45. }
  46. return
  47. }
  48. // UpdateExp user exp.
  49. func (r *RPC) UpdateExp(c context.Context, arg *model.ArgAddExp, res *struct{}) (err error) {
  50. err = r.s.UpdateExp(c, arg)
  51. return
  52. }
  53. // Log get user exp log.
  54. func (r *RPC) Log(c context.Context, arg *model.ArgMid2, res *[]*model.UserLog) (err error) {
  55. *res, err = r.s.ExpLog(c, arg.Mid, arg.RealIP)
  56. return
  57. }
  58. // Stat get user exp stat.
  59. func (r *RPC) Stat(c context.Context, arg *model.ArgMid2, res *model.ExpStat) (err error) {
  60. v, err := r.s.Stat(c, arg.Mid)
  61. if err == nil && v != nil {
  62. *res = *v
  63. }
  64. return
  65. }