rpc.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package gorpc
  2. import (
  3. pb "go-common/app/service/main/sms/api"
  4. "go-common/app/service/main/sms/conf"
  5. "go-common/app/service/main/sms/model"
  6. "go-common/app/service/main/sms/service"
  7. "go-common/library/net/rpc"
  8. "go-common/library/net/rpc/context"
  9. "go-common/library/net/rpc/interceptor"
  10. )
  11. // RPC rpc server
  12. type RPC struct {
  13. s *service.Service
  14. }
  15. // New new rpc server.
  16. func New(c *conf.Config, s *service.Service) (svr *rpc.Server) {
  17. r := &RPC{s: s}
  18. svr = rpc.NewServer(c.RPCServer)
  19. in := interceptor.NewInterceptor("")
  20. svr.Interceptor = in
  21. if err := svr.Register(r); err != nil {
  22. panic(err)
  23. }
  24. return
  25. }
  26. // Send rpc send.
  27. func (r *RPC) Send(c context.Context, a *model.ArgSend, res *struct{}) (err error) {
  28. req := &pb.SendReq{Mid: a.Mid, Mobile: a.Mobile, Country: a.Country, Tcode: a.Tcode, Tparam: a.Tparam}
  29. _, err = r.s.Send(c, req)
  30. return
  31. }
  32. // SendBatch rpc sendbatch.
  33. func (r *RPC) SendBatch(c context.Context, a *model.ArgSendBatch, res *struct{}) (err error) {
  34. req := &pb.SendBatchReq{Mids: a.Mids, Mobiles: a.Mobiles, Tcode: a.Tcode, Tparam: a.Tparam}
  35. _, err = r.s.SendBatch(c, req)
  36. return
  37. }