[#83] services/util: Add meta header methods to ResponseMessage

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-10-22 14:02:40 +03:00 committed by Alex Vanin
parent 71a06f9e01
commit 1cc7983c4e

View file

@ -4,12 +4,16 @@ import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"github.com/nspcc-dev/neofs-api-go/v2/session"
"github.com/nspcc-dev/neofs-api-go/v2/signature" "github.com/nspcc-dev/neofs-api-go/v2/signature"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
// ResponseMessage is an interface of NeoFS response message. // ResponseMessage is an interface of NeoFS response message.
type ResponseMessage interface{} type ResponseMessage interface {
GetMetaHeader() *session.ResponseMetaHeader
SetMetaHeader(*session.ResponseMetaHeader)
}
type UnaryHandler func(context.Context, interface{}) (ResponseMessage, error) type UnaryHandler func(context.Context, interface{}) (ResponseMessage, error)
@ -54,7 +58,7 @@ func (s *RequestMessageStreamer) Send(req interface{}) error {
return s.send(req) return s.send(req)
} }
func (s *RequestMessageStreamer) CloseAndRecv() (interface{}, error) { func (s *RequestMessageStreamer) CloseAndRecv() (ResponseMessage, error) {
resp, err := s.close() resp, err := s.close()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not close stream and receive response") return nil, errors.Wrap(err, "could not close stream and receive response")
@ -75,7 +79,7 @@ func (s *SignService) CreateRequestStreamer(sender RequestMessageWriter, closer
} }
} }
func (s *ResponseMessageStreamer) Recv() (interface{}, error) { func (s *ResponseMessageStreamer) Recv() (ResponseMessage, error) {
m, err := s.recv() m, err := s.recv()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not receive response message for signing") return nil, errors.Wrap(err, "could not receive response message for signing")
@ -105,7 +109,7 @@ func (s *SignService) HandleServerStreamRequest(ctx context.Context, req interfa
}, nil }, nil
} }
func (s *SignService) HandleUnaryRequest(ctx context.Context, req interface{}, handler UnaryHandler) (interface{}, error) { func (s *SignService) HandleUnaryRequest(ctx context.Context, req interface{}, handler UnaryHandler) (ResponseMessage, error) {
// verify request signatures // verify request signatures
if err := signature.VerifyServiceMessage(req); err != nil { if err := signature.VerifyServiceMessage(req); err != nil {
return nil, errors.Wrap(err, "could not verify request") return nil, errors.Wrap(err, "could not verify request")