forked from TrueCloudLab/frostfs-node
[#12] services/session: Implement execution service
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
7b56633185
commit
de12d751e9
1 changed files with 41 additions and 0 deletions
41
pkg/services/session/executor.go
Normal file
41
pkg/services/session/executor.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package session
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type ServiceExecutor interface {
|
||||
Create(context.Context, *session.CreateRequestBody) (*session.CreateResponseBody, error)
|
||||
}
|
||||
|
||||
type executorSvc struct {
|
||||
exec ServiceExecutor
|
||||
|
||||
metaHeader *session.ResponseMetaHeader
|
||||
}
|
||||
|
||||
// NewExecutionService wraps ServiceExecutor and returns Session Service interface.
|
||||
//
|
||||
// Passed meta header is attached to all responses.
|
||||
func NewExecutionService(exec ServiceExecutor, metaHdr *session.ResponseMetaHeader) session.Service {
|
||||
return &executorSvc{
|
||||
exec: exec,
|
||||
metaHeader: metaHdr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *executorSvc) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error) {
|
||||
respBody, err := s.exec.Create(ctx, req.GetBody())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not execute Create request")
|
||||
}
|
||||
|
||||
resp := new(session.CreateResponse)
|
||||
resp.SetBody(respBody)
|
||||
resp.SetMetaHeader(s.metaHeader)
|
||||
|
||||
return resp, nil
|
||||
}
|
Loading…
Reference in a new issue