[#294] putsvcv2: Refactor service constructor

Pass required deps as args.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
pull/515/head
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 {
return putsvcV2.NewService(
putsvcV2.WithInternalService(sPut),
putsvcV2.WithKeyStorage(keyStorage),
)
return putsvcV2.NewService(sPut, keyStorage)
}
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.
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 {
c := new(cfg)
for i := range opts {
opts[i](c)
}
func NewService(svc *putsvc.Service, ks *util.KeyStorage) *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) {
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
}
}