frostfs-node/pkg/services/object/put/v2/service.go
Evgenii Stratonikov 8b50b042c4 [#6] services/object: Remove pointer unneeded indirections
All `Service` are accessed by pointer.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-03-01 15:29:54 +03:00

59 lines
1.2 KiB
Go

package putsvc
import (
"context"
"fmt"
"github.com/TrueCloudLab/frostfs-node/pkg/services/object"
putsvc "github.com/TrueCloudLab/frostfs-node/pkg/services/object/put"
"github.com/TrueCloudLab/frostfs-node/pkg/services/object/util"
)
// Service implements Put operation of Object service v2.
type Service struct {
cfg
}
// Option represents Service constructor option.
type Option func(*cfg)
type cfg struct {
svc *putsvc.Service
keyStorage *util.KeyStorage
}
// NewService constructs Service instance from provided options.
func NewService(opts ...Option) *Service {
var s Service
for i := range opts {
opts[i](&s.cfg)
}
return &s
}
// Put calls internal service and returns v2 object streamer.
func (s *Service) Put(ctx context.Context) (object.PutObjectStream, error) {
stream, err := s.svc.Put(ctx)
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 WithInternalService(v *putsvc.Service) Option {
return func(c *cfg) {
c.svc = v
}
}
func WithKeyStorage(ks *util.KeyStorage) Option {
return func(c *cfg) {
c.keyStorage = ks
}
}