[#460] services/util: Remove HandleServerStreamRequest

There is no need in a wrapper with many from-`interface{}` conversions.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2022-12-30 17:55:03 +03:00
parent 167a67f0b8
commit a64dc9ad70
2 changed files with 18 additions and 58 deletions

View file

@ -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,
})
}

View file

@ -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)
}
}