Airat Arifullin
a17c470fdf
* Update version within go.mod; * Fix deprecated frostfs-api-go/v2 package and use frostfs-sdk-go/api instead. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package session
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util/response"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type ServiceExecutor interface {
|
|
Create(context.Context, *session.CreateRequestBody) (*session.CreateResponseBody, error)
|
|
}
|
|
|
|
type executorSvc struct {
|
|
exec ServiceExecutor
|
|
|
|
respSvc *response.Service
|
|
|
|
log *logger.Logger
|
|
}
|
|
|
|
// NewExecutionService wraps ServiceExecutor and returns Session Service interface.
|
|
func NewExecutionService(exec ServiceExecutor, respSvc *response.Service, l *logger.Logger) Server {
|
|
return &executorSvc{
|
|
exec: exec,
|
|
log: l,
|
|
respSvc: respSvc,
|
|
}
|
|
}
|
|
|
|
func (s *executorSvc) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error) {
|
|
s.log.Debug(logs.ServingRequest,
|
|
zap.String("component", "SessionService"),
|
|
zap.String("request", "Create"),
|
|
)
|
|
|
|
respBody, err := s.exec.Create(ctx, req.GetBody())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not execute Create request: %w", err)
|
|
}
|
|
|
|
resp := new(session.CreateResponse)
|
|
resp.SetBody(respBody)
|
|
|
|
s.respSvc.SetMeta(resp)
|
|
return resp, nil
|
|
}
|