[#294] putsvcv2: Refactor service constructor

Pass required deps as args.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-07-06 12:31:03 +03:00 committed by Evgenii Stratonikov
parent 800a685e84
commit ec9b738465
2 changed files with 4 additions and 31 deletions

View file

@ -327,10 +327,7 @@ func createPutSvc(c *cfg, keyStorage *util.KeyStorage) *putsvc.Service {
} }
func createPutSvcV2(sPut *putsvc.Service, keyStorage *util.KeyStorage) *putsvcV2.Service { func createPutSvcV2(sPut *putsvc.Service, keyStorage *util.KeyStorage) *putsvcV2.Service {
return putsvcV2.NewService( return putsvcV2.NewService(sPut, keyStorage)
putsvcV2.WithInternalService(sPut),
putsvcV2.WithKeyStorage(keyStorage),
)
} }
func createSearchSvc(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.TraverserGenerator, coreConstructor *cache.ClientCache) *searchsvc.Service { func createSearchSvc(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.TraverserGenerator, coreConstructor *cache.ClientCache) *searchsvc.Service {

View file

@ -12,27 +12,15 @@ import (
// Service implements Put operation of Object service v2. // Service implements Put operation of Object service v2.
type Service struct { type Service struct {
*cfg
}
// Option represents Service constructor option.
type Option func(*cfg)
type cfg struct {
svc *putsvc.Service svc *putsvc.Service
keyStorage *util.KeyStorage keyStorage *util.KeyStorage
} }
// NewService constructs Service instance from provided options. // NewService constructs Service instance from provided options.
func NewService(opts ...Option) *Service { func NewService(svc *putsvc.Service, ks *util.KeyStorage) *Service {
c := new(cfg)
for i := range opts {
opts[i](c)
}
return &Service{ return &Service{
cfg: c, svc: svc,
keyStorage: ks,
} }
} }
@ -52,15 +40,3 @@ func (s *Service) Put() (object.PutObjectStream, error) {
func (s *Service) PutSingle(ctx context.Context, req *objectAPI.PutSingleRequest) (*objectAPI.PutSingleResponse, error) { func (s *Service) PutSingle(ctx context.Context, req *objectAPI.PutSingleRequest) (*objectAPI.PutSingleResponse, error) {
return s.svc.PutSingle(ctx, req) return s.svc.PutSingle(ctx, req)
} }
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
}
}