From 71a06f9e01dd1797d64e743f7639038a34b160d1 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 22 Oct 2020 11:03:34 +0300 Subject: [PATCH] [#83] services/util: Define type of response message interface Signed-off-by: Leonard Lyubich --- pkg/services/accounting/sign.go | 2 +- pkg/services/container/sign.go | 12 ++++++------ pkg/services/netmap/sign.go | 2 +- pkg/services/object/sign.go | 14 +++++++------- pkg/services/session/sign.go | 2 +- pkg/services/util/sign.go | 9 ++++++--- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/pkg/services/accounting/sign.go b/pkg/services/accounting/sign.go index 85a0fb7f..f3545e7e 100644 --- a/pkg/services/accounting/sign.go +++ b/pkg/services/accounting/sign.go @@ -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)) }, ) diff --git a/pkg/services/container/sign.go b/pkg/services/container/sign.go index 6890de92..f8a4700f 100644 --- a/pkg/services/container/sign.go +++ b/pkg/services/container/sign.go @@ -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)) }, ) diff --git a/pkg/services/netmap/sign.go b/pkg/services/netmap/sign.go index 57018c41..0eef0d81 100644 --- a/pkg/services/netmap/sign.go +++ b/pkg/services/netmap/sign.go @@ -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)) }, ) diff --git a/pkg/services/object/sign.go b/pkg/services/object/sign.go index 95decd04..908d3c03 100644 --- a/pkg/services/object/sign.go +++ b/pkg/services/object/sign.go @@ -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)) }, ) diff --git a/pkg/services/session/sign.go b/pkg/services/session/sign.go index c7dd98a1..c318b1b9 100644 --- a/pkg/services/session/sign.go +++ b/pkg/services/session/sign.go @@ -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)) }, ) diff --git a/pkg/services/util/sign.go b/pkg/services/util/sign.go index 0ff416dc..6264e4f7 100644 --- a/pkg/services/util/sign.go +++ b/pkg/services/util/sign.go @@ -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