rpc.go 876 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package rpc
  2. import (
  3. "go-common/app/service/main/figure/conf"
  4. "go-common/app/service/main/figure/model"
  5. "go-common/app/service/main/figure/service"
  6. "go-common/library/net/rpc"
  7. "go-common/library/net/rpc/context"
  8. )
  9. // RPC server def.
  10. type RPC struct {
  11. s *service.Service
  12. }
  13. // New init rpc.
  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 rpc server health.
  23. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  24. return
  25. }
  26. // UserFigure get user figure & rank info.
  27. func (r *RPC) UserFigure(c context.Context, arg *model.ArgUserFigure, res *model.FigureWithRank) (err error) {
  28. var fr *model.FigureWithRank
  29. if fr, err = r.s.FigureWithRank(c, arg.Mid); fr != nil {
  30. *res = *fr
  31. }
  32. return
  33. }