rpc.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package rpc
  2. import (
  3. "go-common/app/service/main/secure/conf"
  4. model "go-common/app/service/main/secure/model"
  5. "go-common/app/service/main/secure/service"
  6. "go-common/library/net/rpc"
  7. "go-common/library/net/rpc/context"
  8. )
  9. // RPC rpc service.
  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 connection success.
  23. func (r *RPC) Ping(c context.Context, arg *struct{}, res *struct{}) (err error) {
  24. return
  25. }
  26. // Status rpc status.
  27. func (r *RPC) Status(c context.Context, a *model.ArgSecure, res *model.Msg) (err error) {
  28. var tmp *model.Msg
  29. if tmp, err = r.s.Status(c, a.Mid, a.UUID); err == nil && tmp != nil {
  30. *res = *tmp
  31. }
  32. return
  33. }
  34. // CloseNotify rpc close notify.
  35. func (r *RPC) CloseNotify(c context.Context, arg *model.ArgSecure, res *struct{}) (err error) {
  36. err = r.s.CloseNotify(c, arg.Mid, arg.UUID)
  37. return
  38. }
  39. // AddFeedBack rpc add feedback.
  40. func (r *RPC) AddFeedBack(c context.Context, arg *model.ArgFeedBack, res *struct{}) (err error) {
  41. err = r.s.AddFeedBack(c, arg.Mid, arg.Ts, arg.Type, arg.IP)
  42. return
  43. }
  44. // ExpectionLoc rpc expection loc list.
  45. func (r *RPC) ExpectionLoc(c context.Context, arg *model.ArgSecure, res *[]*model.Expection) (err error) {
  46. *res, err = r.s.ExpectionLoc(c, arg.Mid)
  47. return
  48. }