[#891] getSvc: Refactor Get service V2 creation
All checks were successful
DCO action / DCO (pull_request) Successful in 2m46s
Vulncheck / Vulncheck (pull_request) Successful in 2m53s
Build / Build Components (1.20) (pull_request) Successful in 4m31s
Build / Build Components (1.21) (pull_request) Successful in 4m26s
Tests and linters / Lint (pull_request) Successful in 6m9s
Tests and linters / Staticcheck (pull_request) Successful in 6m7s
Tests and linters / Tests (1.20) (pull_request) Successful in 8m27s
Tests and linters / Tests (1.21) (pull_request) Successful in 9m4s
Tests and linters / Tests with -race (pull_request) Successful in 9m48s

Use arguments for mandatory fields.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2024-01-12 10:05:29 +03:00
parent 394f086fe2
commit 52ffa9f164
3 changed files with 24 additions and 59 deletions

View file

@ -372,13 +372,12 @@ func createGetService(c *cfg, keyStorage *util.KeyStorage, traverseGen *util.Tra
func createGetServiceV2(c *cfg, sGet *getsvc.Service, keyStorage *util.KeyStorage) *getsvcV2.Service { func createGetServiceV2(c *cfg, sGet *getsvc.Service, keyStorage *util.KeyStorage) *getsvcV2.Service {
return getsvcV2.NewService( return getsvcV2.NewService(
getsvcV2.WithInternalService(sGet), sGet,
getsvcV2.WithKeyStorage(keyStorage), keyStorage,
getsvcV2.WithEpochSource(c.netMapSource), c.clientCache,
getsvcV2.WithClientSource(c.clientCache), c.netMapSource,
getsvcV2.WithContainerSource(c.cfgObject.cnrSource), c,
getsvcV2.WithNetmapSource(c.netMapSource), c.cfgObject.cnrSource,
getsvcV2.WithNetmapAnnouncedKeys(c),
getsvcV2.WithLogger(c.log), getsvcV2.WithLogger(c.log),
) )
} }

View file

@ -71,7 +71,7 @@ func (s *Service) needToForwardGetRangeHashRequest(req *objectV2.GetRangeHashReq
return result, fmt.Errorf("(%T) could not get container: %w", s, err) return result, fmt.Errorf("(%T) could not get container: %w", s, err)
} }
epoch, err := s.epochSource.Epoch() epoch, err := s.netmapSource.Epoch()
if err != nil { if err != nil {
return result, fmt.Errorf("(%T) could not get epoch: %w", s, err) return result, fmt.Errorf("(%T) could not get epoch: %w", s, err)
} }

View file

@ -24,10 +24,6 @@ type Service struct {
// Option represents Service constructor option. // Option represents Service constructor option.
type Option func(*cfg) type Option func(*cfg)
type epochSource interface {
Epoch() (uint64, error)
}
type clientSource interface { type clientSource interface {
Get(info clientcore.NodeInfo) (clientcore.MultiAddressClient, error) Get(info clientcore.NodeInfo) (clientcore.MultiAddressClient, error)
} }
@ -37,8 +33,6 @@ type cfg struct {
keyStorage *objutil.KeyStorage keyStorage *objutil.KeyStorage
epochSource epochSource
clientSource clientSource clientSource clientSource
netmapSource netmap.Source netmapSource netmap.Source
@ -51,8 +45,23 @@ type cfg struct {
} }
// NewService constructs Service instance from provided options. // NewService constructs Service instance from provided options.
func NewService(opts ...Option) *Service { func NewService(svc *getsvc.Service,
c := new(cfg) keyStorage *objutil.KeyStorage,
clientSource clientSource,
netmapSource netmap.Source,
announcedKeys netmap.AnnouncedKeys,
contSource container.Source,
opts ...Option,
) *Service {
c := &cfg{
svc: svc,
keyStorage: keyStorage,
clientSource: clientSource,
netmapSource: netmapSource,
announcedKeys: announcedKeys,
contSource: contSource,
log: &logger.Logger{Logger: zap.L()},
}
for i := range opts { for i := range opts {
opts[i](c) opts[i](c)
@ -123,49 +132,6 @@ func (s *Service) Head(ctx context.Context, req *objectV2.HeadRequest) (*objectV
return resp, err return resp, err
} }
func WithInternalService(v *getsvc.Service) Option {
return func(c *cfg) {
c.svc = v
}
}
// WithKeyStorage returns option to set local private key storage.
func WithKeyStorage(ks *objutil.KeyStorage) Option {
return func(c *cfg) {
c.keyStorage = ks
}
}
func WithEpochSource(es epochSource) Option {
return func(c *cfg) {
c.epochSource = es
}
}
func WithClientSource(cs clientSource) Option {
return func(c *cfg) {
c.clientSource = cs
}
}
func WithNetmapSource(ns netmap.Source) Option {
return func(c *cfg) {
c.netmapSource = ns
}
}
func WithNetmapAnnouncedKeys(ak netmap.AnnouncedKeys) Option {
return func(c *cfg) {
c.announcedKeys = ak
}
}
func WithContainerSource(cs container.Source) Option {
return func(c *cfg) {
c.contSource = cs
}
}
func WithLogger(l *logger.Logger) Option { func WithLogger(l *logger.Logger) Option {
return func(c *cfg) { return func(c *cfg) {
c.log = &logger.Logger{Logger: l.With(zap.String("component", "Object.Get V2 service"))} c.log = &logger.Logger{Logger: l.With(zap.String("component", "Object.Get V2 service"))}