[#294] deletesvc: 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:04:00 +03:00 committed by Evgenii Stratonikov
parent a476d8285a
commit 1420b8b9ea
2 changed files with 21 additions and 51 deletions

View file

@ -382,17 +382,17 @@ func createGetServiceV2(sGet *getsvc.Service, keyStorage *util.KeyStorage) *gets
func createDeleteService(c *cfg, keyStorage *util.KeyStorage, sGet *getsvc.Service,
sSearch *searchsvc.Service, sPut *putsvc.Service) *deletesvc.Service {
return deletesvc.New(
deletesvc.WithLogger(c.log),
deletesvc.WithHeadService(sGet),
deletesvc.WithSearchService(sSearch),
deletesvc.WithPutService(sPut),
deletesvc.WithNetworkInfo(&delNetInfo{
sGet,
sSearch,
sPut,
&delNetInfo{
State: c.cfgNetmap.state,
tsLifetime: c.cfgObject.tombstoneLifetime,
cfg: c,
}),
deletesvc.WithKeyStorage(keyStorage),
},
keyStorage,
deletesvc.WithLogger(c.log),
)
}

View file

@ -62,16 +62,22 @@ type cfg struct {
keyStorage *util.KeyStorage
}
func defaultCfg() *cfg {
return &cfg{
log: &logger.Logger{Logger: zap.L()},
}
}
// New creates, initializes and returns utility serving
// Object.Get service requests.
func New(opts ...Option) *Service {
c := defaultCfg()
func New(gs *getsvc.Service,
ss *searchsvc.Service,
ps *putsvc.Service,
ni NetworkInfo,
ks *util.KeyStorage,
opts ...Option) *Service {
c := &cfg{
log: &logger.Logger{Logger: zap.L()},
header: (*headSvcWrapper)(gs),
searcher: (*searchSvcWrapper)(ss),
placer: (*putSvcWrapper)(ps),
netInfo: ni,
keyStorage: ks,
}
for i := range opts {
opts[i](c)
@ -88,39 +94,3 @@ func WithLogger(l *logger.Logger) Option {
c.log = &logger.Logger{Logger: l.With(zap.String("component", "objectSDK.Delete service"))}
}
}
// WithHeadService returns option to set Head service
// to work with object headers.
func WithHeadService(h *getsvc.Service) Option {
return func(c *cfg) {
c.header = (*headSvcWrapper)(h)
}
}
// WithSearchService returns option to set search service.
func WithSearchService(s *searchsvc.Service) Option {
return func(c *cfg) {
c.searcher = (*searchSvcWrapper)(s)
}
}
// WithPutService returns option to specify put service.
func WithPutService(p *putsvc.Service) Option {
return func(c *cfg) {
c.placer = (*putSvcWrapper)(p)
}
}
// WithNetworkInfo returns option to set network information source.
func WithNetworkInfo(netInfo NetworkInfo) Option {
return func(c *cfg) {
c.netInfo = netInfo
}
}
// WithKeyStorage returns option to set local private key storage.
func WithKeyStorage(ks *util.KeyStorage) Option {
return func(c *cfg) {
c.keyStorage = ks
}
}