forked from TrueCloudLab/frostfs-node
[#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:
parent
1cc7983c4e
commit
6bede7d836
4 changed files with 166 additions and 0 deletions
21
pkg/services/util/response/unary.go
Normal file
21
pkg/services/util/response/unary.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue