diff --git a/pkg/services/object/acl/eacl/v2/headers.go b/pkg/services/object/acl/eacl/v2/headers.go index ae3bc85689..3d09e84b02 100644 --- a/pkg/services/object/acl/eacl/v2/headers.go +++ b/pkg/services/object/acl/eacl/v2/headers.go @@ -45,31 +45,30 @@ type headerSource struct { incompleteObjectHeaders bool } -func defaultCfg() *cfg { - return &cfg{ - storage: new(localStorage), - } +func (c *cfg) initDefault() { + c.storage = new(localStorage) } func NewMessageHeaderSource(opts ...Option) (eaclSDK.TypedHeaderSource, error) { - cfg := defaultCfg() + var c cfg + c.initDefault() for i := range opts { - opts[i](cfg) + opts[i](&c) } - if cfg.msg == nil { + if c.msg == nil { return nil, errors.New("message is not provided") } var res headerSource - err := cfg.readObjectHeaders(&res) + err := c.readObjectHeaders(&res) if err != nil { return nil, err } - res.requestHeaders = requestHeaders(cfg.msg) + res.requestHeaders = requestHeaders(c.msg) return res, nil } diff --git a/pkg/services/object/acl/v2/service.go b/pkg/services/object/acl/v2/service.go index 6bf8c44058..93acec224d 100644 --- a/pkg/services/object/acl/v2/service.go +++ b/pkg/services/object/acl/v2/service.go @@ -21,7 +21,7 @@ import ( // Service checks basic ACL rules. type Service struct { - *cfg + cfg c senderClassifier } @@ -72,18 +72,17 @@ type cfg struct { next object.ServiceServer } -func defaultCfg() *cfg { - return &cfg{ - log: &logger.Logger{Logger: zap.L()}, - } +func (c *cfg) initDefault() { + c.log = &logger.Logger{Logger: zap.L()} } // New is a constructor for object ACL checking service. -func New(opts ...Option) Service { - cfg := defaultCfg() +func New(opts ...Option) *Service { + var s Service + s.cfg.initDefault() for i := range opts { - opts[i](cfg) + opts[i](&s.cfg) } panicOnNil := func(v any, name string) { @@ -92,20 +91,18 @@ func New(opts ...Option) Service { } } - panicOnNil(cfg.next, "next Service") - panicOnNil(cfg.nm, "netmap client") - panicOnNil(cfg.irFetcher, "inner Ring fetcher") - panicOnNil(cfg.checker, "acl checker") - panicOnNil(cfg.containers, "container source") + panicOnNil(s.cfg.next, "next Service") + panicOnNil(s.cfg.nm, "netmap client") + panicOnNil(s.cfg.irFetcher, "inner Ring fetcher") + panicOnNil(s.cfg.checker, "acl checker") + panicOnNil(s.cfg.containers, "container source") - return Service{ - cfg: cfg, - c: senderClassifier{ - log: cfg.log, - innerRing: cfg.irFetcher, - netmap: cfg.nm, - }, + s.c = senderClassifier{ + log: s.cfg.log, + innerRing: s.cfg.irFetcher, + netmap: s.cfg.nm, } + return &s } // Get implements ServiceServer interface, makes ACL checks and calls diff --git a/pkg/services/object/delete/service.go b/pkg/services/object/delete/service.go index f2ea384de1..6e490ce782 100644 --- a/pkg/services/object/delete/service.go +++ b/pkg/services/object/delete/service.go @@ -15,7 +15,7 @@ import ( // Service utility serving requests of Object.Get service. type Service struct { - *cfg + cfg } // Option is a Service's constructor option. @@ -60,24 +60,21 @@ type cfg struct { keyStorage *util.KeyStorage } -func defaultCfg() *cfg { - return &cfg{ - log: &logger.Logger{Logger: zap.L()}, - } +func (c *cfg) initDefault() { + c.log = &logger.Logger{Logger: zap.L()} } // New creates, initializes and returns utility serving // Object.Get service requests. func New(opts ...Option) *Service { - c := defaultCfg() + var s Service + s.cfg.initDefault() for i := range opts { - opts[i](c) + opts[i](&s.cfg) } - return &Service{ - cfg: c, - } + return &s } // WithLogger returns option to specify Delete service's logger. diff --git a/pkg/services/object/delete/v2/service.go b/pkg/services/object/delete/v2/service.go index 51759c5df5..bbb119f89f 100644 --- a/pkg/services/object/delete/v2/service.go +++ b/pkg/services/object/delete/v2/service.go @@ -9,7 +9,7 @@ import ( // Service implements Delete operation of Object service v2. type Service struct { - *cfg + cfg } // Option represents Service constructor option. @@ -21,15 +21,13 @@ type cfg struct { // NewService constructs Service instance from provided options. func NewService(opts ...Option) *Service { - c := new(cfg) + var s Service for i := range opts { - opts[i](c) + opts[i](&s.cfg) } - return &Service{ - cfg: c, - } + return &s } // Delete calls internal service. diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index f6645bbd58..531dde58b3 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -245,7 +245,7 @@ func TestGetLocalOnly(t *testing.T) { ctx := context.Background() newSvc := func(storage *testStorage) *Service { - svc := &Service{cfg: new(cfg)} + svc := &Service{} svc.log = test.NewLogger(false) svc.localStorage = storage @@ -506,7 +506,7 @@ func TestGetRemoteSmall(t *testing.T) { container.CalculateID(&idCnr, cnr) newSvc := func(b *testPlacementBuilder, c *testClientCache) *Service { - svc := &Service{cfg: new(cfg)} + svc := &Service{} svc.log = test.NewLogger(false) svc.localStorage = newTestStorage() @@ -1639,7 +1639,7 @@ func TestGetFromPastEpoch(t *testing.T) { c22 := newTestClient() c22.addResult(addr, obj, nil) - svc := &Service{cfg: new(cfg)} + svc := &Service{} svc.log = test.NewLogger(false) svc.localStorage = newTestStorage() diff --git a/pkg/services/object/get/service.go b/pkg/services/object/get/service.go index fe4ba4c239..b52c163848 100644 --- a/pkg/services/object/get/service.go +++ b/pkg/services/object/get/service.go @@ -15,7 +15,7 @@ import ( // Service utility serving requests of Object.Get service. type Service struct { - *cfg + cfg } // Option is a Service's constructor option. @@ -49,26 +49,23 @@ type epochSource interface { Epoch() (uint64, error) } -func defaultCfg() *cfg { - return &cfg{ - log: &logger.Logger{Logger: zap.L()}, - localStorage: new(storageEngineWrapper), - clientCache: new(clientCacheWrapper), - } +func (c *cfg) initDefault() { + c.log = &logger.Logger{Logger: zap.L()} + c.localStorage = new(storageEngineWrapper) + c.clientCache = new(clientCacheWrapper) } // New creates, initializes and returns utility serving // Object.Get service requests. func New(opts ...Option) *Service { - c := defaultCfg() + var s Service + s.cfg.initDefault() for i := range opts { - opts[i](c) + opts[i](&s.cfg) } - return &Service{ - cfg: c, - } + return &s } // WithLogger returns option to specify Get service's logger. diff --git a/pkg/services/object/get/v2/service.go b/pkg/services/object/get/v2/service.go index 3fd8cd04a0..7715768183 100644 --- a/pkg/services/object/get/v2/service.go +++ b/pkg/services/object/get/v2/service.go @@ -13,7 +13,7 @@ import ( // Service implements Get operation of Object service v2. type Service struct { - *cfg + cfg } // Option represents Service constructor option. @@ -27,15 +27,13 @@ type cfg struct { // NewService constructs Service instance from provided options. func NewService(opts ...Option) *Service { - c := new(cfg) + var s Service for i := range opts { - opts[i](c) + opts[i](&s.cfg) } - return &Service{ - cfg: c, - } + return &s } // Get calls internal service and returns v2 object stream. diff --git a/pkg/services/object/put/service.go b/pkg/services/object/put/service.go index b74c97d490..cfc20ca28f 100644 --- a/pkg/services/object/put/service.go +++ b/pkg/services/object/put/service.go @@ -22,7 +22,7 @@ type MaxSizeSource interface { } type Service struct { - *cfg + cfg } type Option func(*cfg) @@ -57,31 +57,28 @@ type cfg struct { log *logger.Logger } -func defaultCfg() *cfg { - return &cfg{ - remotePool: util.NewPseudoWorkerPool(), - localPool: util.NewPseudoWorkerPool(), - log: &logger.Logger{Logger: zap.L()}, - } +func (c *cfg) initDefault() { + c.remotePool = util.NewPseudoWorkerPool() + c.localPool = util.NewPseudoWorkerPool() + c.log = &logger.Logger{Logger: zap.L()} } func NewService(opts ...Option) *Service { - c := defaultCfg() + var s Service + s.cfg.initDefault() for i := range opts { - opts[i](c) + opts[i](&s.cfg) } - c.fmtValidator = object.NewFormatValidator(c.fmtValidatorOpts...) + s.cfg.fmtValidator = object.NewFormatValidator(s.cfg.fmtValidatorOpts...) - return &Service{ - cfg: c, - } + return &s } func (p *Service) Put(ctx context.Context) (*Streamer, error) { return &Streamer{ - cfg: p.cfg, + cfg: &p.cfg, ctx: ctx, }, nil } diff --git a/pkg/services/object/put/v2/service.go b/pkg/services/object/put/v2/service.go index 7d0dfc6135..254c9b99a3 100644 --- a/pkg/services/object/put/v2/service.go +++ b/pkg/services/object/put/v2/service.go @@ -11,7 +11,7 @@ import ( // Service implements Put operation of Object service v2. type Service struct { - *cfg + cfg } // Option represents Service constructor option. @@ -24,15 +24,13 @@ type cfg struct { // NewService constructs Service instance from provided options. func NewService(opts ...Option) *Service { - c := new(cfg) + var s Service for i := range opts { - opts[i](c) + opts[i](&s.cfg) } - return &Service{ - cfg: c, - } + return &s } // Put calls internal service and returns v2 object streamer. diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index 25e5838c53..fc84508b64 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -146,7 +146,7 @@ func TestGetLocalOnly(t *testing.T) { ctx := context.Background() newSvc := func(storage *testStorage) *Service { - svc := &Service{cfg: new(cfg)} + svc := &Service{} svc.log = test.NewLogger(false) svc.localStorage = storage @@ -248,7 +248,7 @@ func TestGetRemoteSmall(t *testing.T) { container.CalculateID(&id, cnr) newSvc := func(b *testPlacementBuilder, c *testClientCache) *Service { - svc := &Service{cfg: new(cfg)} + svc := &Service{} svc.log = test.NewLogger(false) svc.localStorage = newTestStorage() @@ -357,7 +357,7 @@ func TestGetFromPastEpoch(t *testing.T) { ids22 := generateIDs(10) c22.addResult(idCnr, ids22, nil) - svc := &Service{cfg: new(cfg)} + svc := &Service{} svc.log = test.NewLogger(false) svc.localStorage = newTestStorage() diff --git a/pkg/services/object/search/service.go b/pkg/services/object/search/service.go index 09b277b27e..79cf22503d 100644 --- a/pkg/services/object/search/service.go +++ b/pkg/services/object/search/service.go @@ -15,7 +15,7 @@ import ( // Service is an utility serving requests // of Object.Search service. type Service struct { - *cfg + cfg } // Option is a Service's constructor option. @@ -55,25 +55,22 @@ type epochSource interface { Epoch() (uint64, error) } -func defaultCfg() *cfg { - return &cfg{ - log: &logger.Logger{Logger: zap.L()}, - clientConstructor: new(clientConstructorWrapper), - } +func (c *cfg) initDefault() { + c.log = &logger.Logger{Logger: zap.L()} + c.clientConstructor = new(clientConstructorWrapper) } // New creates, initializes and returns utility serving // Object.Get service requests. func New(opts ...Option) *Service { - c := defaultCfg() + var s Service + s.cfg.initDefault() for i := range opts { - opts[i](c) + opts[i](&s.cfg) } - return &Service{ - cfg: c, - } + return &s } // WithLogger returns option to specify Get service's logger. diff --git a/pkg/services/object/search/v2/service.go b/pkg/services/object/search/v2/service.go index 17e1bc7e04..b6c25223c4 100644 --- a/pkg/services/object/search/v2/service.go +++ b/pkg/services/object/search/v2/service.go @@ -9,7 +9,7 @@ import ( // Service implements Search operation of Object service v2. type Service struct { - *cfg + cfg } // Option represents Service constructor option. @@ -23,15 +23,13 @@ type cfg struct { // NewService constructs Service instance from provided options. func NewService(opts ...Option) *Service { - c := new(cfg) + var s Service for i := range opts { - opts[i](c) + opts[i](&s.cfg) } - return &Service{ - cfg: c, - } + return &s } // Search calls internal service and returns v2 object stream.