frostfs-node/pkg/services/session/executor.go
Leonard Lyubich 718a2fad26 [#425] services: Define service interfaces that was removed from API lib
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-03-17 15:00:37 +03:00

35 lines
808 B
Go

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
}
// NewExecutionService wraps ServiceExecutor and returns Session Service interface.
func NewExecutionService(exec ServiceExecutor) Server {
return &executorSvc{
exec: exec,
}
}
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)
return resp, nil
}