From a64dc9ad7083e2021b202aefffe02d48ce221b5d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 30 Dec 2022 17:55:03 +0300 Subject: [PATCH] [#460] services/util: Remove `HandleServerStreamRequest` There is no need in a wrapper with many from-`interface{}` conversions. Signed-off-by: Evgenii Stratonikov --- pkg/services/object/response.go | 39 ++++++++++----------- pkg/services/util/response/server_stream.go | 37 ------------------- 2 files changed, 18 insertions(+), 58 deletions(-) delete mode 100644 pkg/services/util/response/server_stream.go diff --git a/pkg/services/object/response.go b/pkg/services/object/response.go index 4eef1dfb9..0bec72163 100644 --- a/pkg/services/object/response.go +++ b/pkg/services/object/response.go @@ -16,21 +16,21 @@ type ResponseService struct { } type searchStreamResponser struct { - util.ServerStream + SearchStream - respWriter util.ResponseMessageWriter + respSvc *response.Service } type getStreamResponser struct { - util.ServerStream + GetObjectStream - respWriter util.ResponseMessageWriter + respSvc *response.Service } type getRangeStreamResponser struct { - util.ServerStream + GetObjectRangeStream - respWriter util.ResponseMessageWriter + respSvc *response.Service } type putStreamResponser struct { @@ -47,15 +47,14 @@ func NewResponseService(objSvc ServiceServer, respSvc *response.Service) *Respon } func (s *getStreamResponser) Send(resp *object.GetResponse) error { - return s.respWriter(resp) + s.respSvc.SetMeta(resp) + return s.GetObjectStream.Send(resp) } func (s *ResponseService) Get(req *object.GetRequest, stream GetObjectStream) error { return s.svc.Get(req, &getStreamResponser{ - ServerStream: stream, - respWriter: s.respSvc.HandleServerStreamRequest(func(resp util.ResponseMessage) error { - return stream.Send(resp.(*object.GetResponse)) - }), + GetObjectStream: stream, + respSvc: s.respSvc, }) } @@ -101,15 +100,14 @@ func (s *ResponseService) Head(ctx context.Context, req *object.HeadRequest) (*o } func (s *searchStreamResponser) Send(resp *object.SearchResponse) error { - return s.respWriter(resp) + s.respSvc.SetMeta(resp) + return s.SearchStream.Send(resp) } func (s *ResponseService) Search(req *object.SearchRequest, stream SearchStream) error { return s.svc.Search(req, &searchStreamResponser{ - ServerStream: stream, - respWriter: s.respSvc.HandleServerStreamRequest(func(resp util.ResponseMessage) error { - return stream.Send(resp.(*object.SearchResponse)) - }), + SearchStream: stream, + respSvc: s.respSvc, }) } @@ -124,15 +122,14 @@ func (s *ResponseService) Delete(ctx context.Context, req *object.DeleteRequest) } func (s *getRangeStreamResponser) Send(resp *object.GetRangeResponse) error { - return s.respWriter(resp) + s.respSvc.SetMeta(resp) + return s.GetObjectRangeStream.Send(resp) } func (s *ResponseService) GetRange(req *object.GetRangeRequest, stream GetObjectRangeStream) error { return s.svc.GetRange(req, &getRangeStreamResponser{ - ServerStream: stream, - respWriter: s.respSvc.HandleServerStreamRequest(func(resp util.ResponseMessage) error { - return stream.Send(resp.(*object.GetRangeResponse)) - }), + GetObjectRangeStream: stream, + respSvc: s.respSvc, }) } diff --git a/pkg/services/util/response/server_stream.go b/pkg/services/util/response/server_stream.go deleted file mode 100644 index df1c00177..000000000 --- a/pkg/services/util/response/server_stream.go +++ /dev/null @@ -1,37 +0,0 @@ -package response - -import ( - "fmt" - - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util" -) - -// ServerMessageStreamer represents server-side message streamer -// that sets meta values to all response messages. -type ServerMessageStreamer struct { - srv *Service - - recv util.ResponseMessageReader -} - -// Recv calls Recv method of internal streamer, sets response meta -// values and returns the response. -func (s *ServerMessageStreamer) Recv() (util.ResponseMessage, error) { - m, err := s.recv() - if err != nil { - return nil, fmt.Errorf("could not receive response message for signing: %w", err) - } - - s.srv.SetMeta(m) - - return m, nil -} - -// HandleServerStreamRequest builds internal streamer via handlers, wraps it to ServerMessageStreamer and returns the result. -func (s *Service) HandleServerStreamRequest(respWriter util.ResponseMessageWriter) util.ResponseMessageWriter { - return func(resp util.ResponseMessage) error { - s.SetMeta(resp) - - return respWriter(resp) - } -}