[#83] services/util: Implement response service

Create response package. Implement response Service that sets values of
response meta header.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-10-22 14:04:46 +03:00 committed by Alex Vanin
parent 1cc7983c4e
commit 6bede7d836
4 changed files with 166 additions and 0 deletions

View file

@ -0,0 +1,21 @@
package response
import (
"context"
"github.com/nspcc-dev/neofs-node/pkg/services/util"
"github.com/pkg/errors"
)
// HandleUnaryRequest call passes request to handler, sets response meta header values and returns it.
func (s *Service) HandleUnaryRequest(ctx context.Context, req interface{}, handler util.UnaryHandler) (util.ResponseMessage, error) {
// process request
resp, err := handler(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "could not handle request")
}
setMeta(resp, s.cfg)
return resp, nil
}