2020-10-22 11:04:46 +00:00
|
|
|
package response
|
|
|
|
|
|
|
|
import (
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util"
|
2020-10-22 11:04:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ServerMessageStreamer represents server-side message streamer
|
|
|
|
// that sets meta values to all response messages.
|
|
|
|
type ServerMessageStreamer struct {
|
2022-12-30 14:48:50 +00:00
|
|
|
srv *Service
|
2020-10-22 11:04:46 +00:00
|
|
|
|
|
|
|
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 {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not receive response message for signing: %w", err)
|
2020-10-22 11:04:46 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 14:48:50 +00:00
|
|
|
s.srv.SetMeta(m)
|
2020-10-22 11:04:46 +00:00
|
|
|
|
|
|
|
return m, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// HandleServerStreamRequest builds internal streamer via handlers, wraps it to ServerMessageStreamer and returns the result.
|
2021-01-11 15:17:06 +00:00
|
|
|
func (s *Service) HandleServerStreamRequest(respWriter util.ResponseMessageWriter) util.ResponseMessageWriter {
|
2020-12-02 23:45:25 +00:00
|
|
|
return func(resp util.ResponseMessage) error {
|
2022-12-30 14:48:50 +00:00
|
|
|
s.SetMeta(resp)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
return respWriter(resp)
|
|
|
|
}
|
|
|
|
}
|