frostfs-node/pkg/services/object/put/v2/service.go
Dmitrii Stepanov ec9b738465 [#294] putsvcv2: Refactor service constructor
Pass required deps as args.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-07-12 07:42:10 +00:00

42 lines
1.1 KiB
Go

package putsvc
import (
"context"
"fmt"
objectAPI "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object"
putsvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/put"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
)
// Service implements Put operation of Object service v2.
type Service struct {
svc *putsvc.Service
keyStorage *util.KeyStorage
}
// NewService constructs Service instance from provided options.
func NewService(svc *putsvc.Service, ks *util.KeyStorage) *Service {
return &Service{
svc: svc,
keyStorage: ks,
}
}
// Put calls internal service and returns v2 object streamer.
func (s *Service) Put() (object.PutObjectStream, error) {
stream, err := s.svc.Put()
if err != nil {
return nil, fmt.Errorf("(%T) could not open object put stream: %w", s, err)
}
return &streamer{
stream: stream,
keyStorage: s.keyStorage,
}, nil
}
func (s *Service) PutSingle(ctx context.Context, req *objectAPI.PutSingleRequest) (*objectAPI.PutSingleResponse, error) {
return s.svc.PutSingle(ctx, req)
}