[#83] services/util: Define type of response message interface

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-10-22 11:03:34 +03:00 committed by Alex Vanin
parent 7464254680
commit 71a06f9e01
6 changed files with 22 additions and 19 deletions

View file

@ -23,7 +23,7 @@ func NewSignService(key *ecdsa.PrivateKey, svc accounting.Service) accounting.Se
func (s *signService) Balance(ctx context.Context, req *accounting.BalanceRequest) (*accounting.BalanceResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (interface{}, error) {
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.Balance(ctx, req.(*accounting.BalanceRequest))
},
)

View file

@ -23,7 +23,7 @@ func NewSignService(key *ecdsa.PrivateKey, svc container.Service) container.Serv
func (s *signService) Put(ctx context.Context, req *container.PutRequest) (*container.PutResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (interface{}, error) {
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.Put(ctx, req.(*container.PutRequest))
},
)
@ -36,7 +36,7 @@ func (s *signService) Put(ctx context.Context, req *container.PutRequest) (*cont
func (s *signService) Delete(ctx context.Context, req *container.DeleteRequest) (*container.DeleteResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (interface{}, error) {
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.Delete(ctx, req.(*container.DeleteRequest))
},
)
@ -49,7 +49,7 @@ func (s *signService) Delete(ctx context.Context, req *container.DeleteRequest)
func (s *signService) Get(ctx context.Context, req *container.GetRequest) (*container.GetResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (interface{}, error) {
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.Get(ctx, req.(*container.GetRequest))
},
)
@ -62,7 +62,7 @@ func (s *signService) Get(ctx context.Context, req *container.GetRequest) (*cont
func (s *signService) List(ctx context.Context, req *container.ListRequest) (*container.ListResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (interface{}, error) {
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.List(ctx, req.(*container.ListRequest))
},
)
@ -75,7 +75,7 @@ func (s *signService) List(ctx context.Context, req *container.ListRequest) (*co
func (s *signService) SetExtendedACL(ctx context.Context, req *container.SetExtendedACLRequest) (*container.SetExtendedACLResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (interface{}, error) {
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.SetExtendedACL(ctx, req.(*container.SetExtendedACLRequest))
},
)
@ -88,7 +88,7 @@ func (s *signService) SetExtendedACL(ctx context.Context, req *container.SetExte
func (s *signService) GetExtendedACL(ctx context.Context, req *container.GetExtendedACLRequest) (*container.GetExtendedACLResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (interface{}, error) {
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.GetExtendedACL(ctx, req.(*container.GetExtendedACLRequest))
},
)

View file

@ -26,7 +26,7 @@ func (s *signService) LocalNodeInfo(
req *netmap.LocalNodeInfoRequest) (*netmap.LocalNodeInfoResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (interface{}, error) {
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.LocalNodeInfo(ctx, req.(*netmap.LocalNodeInfoRequest))
},
)

View file

@ -58,7 +58,7 @@ func (s *signService) Get(ctx context.Context, req *object.GetRequest) (object.G
return nil, err
}
return func() (interface{}, error) {
return func() (util.ResponseMessage, error) {
return stream.Recv()
}, nil
},
@ -96,7 +96,7 @@ func (s *signService) Put(ctx context.Context) (object.PutObjectStreamer, error)
func(req interface{}) error {
return stream.Send(req.(*object.PutRequest))
},
func() (interface{}, error) {
func() (util.ResponseMessage, error) {
return stream.CloseAndRecv()
},
),
@ -105,7 +105,7 @@ func (s *signService) Put(ctx context.Context) (object.PutObjectStreamer, error)
func (s *signService) Head(ctx context.Context, req *object.HeadRequest) (*object.HeadResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (interface{}, error) {
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.Head(ctx, req.(*object.HeadRequest))
},
)
@ -133,7 +133,7 @@ func (s *signService) Search(ctx context.Context, req *object.SearchRequest) (ob
return nil, err
}
return func() (interface{}, error) {
return func() (util.ResponseMessage, error) {
return stream.Recv()
}, nil
},
@ -149,7 +149,7 @@ func (s *signService) Search(ctx context.Context, req *object.SearchRequest) (ob
func (s *signService) Delete(ctx context.Context, req *object.DeleteRequest) (*object.DeleteResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (interface{}, error) {
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.Delete(ctx, req.(*object.DeleteRequest))
},
)
@ -177,7 +177,7 @@ func (s *signService) GetRange(ctx context.Context, req *object.GetRangeRequest)
return nil, err
}
return func() (interface{}, error) {
return func() (util.ResponseMessage, error) {
return stream.Recv()
}, nil
},
@ -193,7 +193,7 @@ func (s *signService) GetRange(ctx context.Context, req *object.GetRangeRequest)
func (s *signService) GetRangeHash(ctx context.Context, req *object.GetRangeHashRequest) (*object.GetRangeHashResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (interface{}, error) {
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.GetRangeHash(ctx, req.(*object.GetRangeHashRequest))
},
)

View file

@ -23,7 +23,7 @@ func NewSignService(key *ecdsa.PrivateKey, svc session.Service) session.Service
func (s *signService) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error) {
resp, err := s.sigSvc.HandleUnaryRequest(ctx, req,
func(ctx context.Context, req interface{}) (interface{}, error) {
func(ctx context.Context, req interface{}) (util.ResponseMessage, error) {
return s.svc.Create(ctx, req.(*session.CreateRequest))
},
)

View file

@ -8,7 +8,10 @@ import (
"github.com/pkg/errors"
)
type UnaryHandler func(context.Context, interface{}) (interface{}, error)
// ResponseMessage is an interface of NeoFS response message.
type ResponseMessage interface{}
type UnaryHandler func(context.Context, interface{}) (ResponseMessage, error)
type SignService struct {
key *ecdsa.PrivateKey
@ -16,7 +19,7 @@ type SignService struct {
type ServerStreamHandler func(context.Context, interface{}) (ResponseMessageReader, error)
type ResponseMessageReader func() (interface{}, error)
type ResponseMessageReader func() (ResponseMessage, error)
type ResponseMessageStreamer struct {
key *ecdsa.PrivateKey
@ -26,7 +29,7 @@ type ResponseMessageStreamer struct {
type RequestMessageWriter func(interface{}) error
type ClientStreamCloser func() (interface{}, error)
type ClientStreamCloser func() (ResponseMessage, error)
type RequestMessageStreamer struct {
key *ecdsa.PrivateKey