[#6] services/object: Remove pointer unneeded indirections

All `Service` are accessed by pointer.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2022-12-30 14:19:42 +03:00
parent c1cd32ecca
commit 9ca20ad80f
12 changed files with 82 additions and 106 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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.

View file

@ -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.

View file

@ -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()

View file

@ -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.

View file

@ -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.

View file

@ -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
}

View file

@ -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.

View file

@ -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()

View file

@ -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.

View file

@ -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.