From 16543a190433a0ec3807d24befcabce2266aa712 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 15 Mar 2022 22:40:31 +0300 Subject: [PATCH] [#1243] node/object: Hide engine behind interface Do not use engine as explicit dependency in the put service. This allows wrapping storage engine. Signed-off-by: Pavel Karpy --- pkg/services/object/put/local.go | 13 ++++++++++--- pkg/services/object/put/service.go | 5 ++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/services/object/put/local.go b/pkg/services/object/put/local.go index 99ff2217b..b4f04e626 100644 --- a/pkg/services/object/put/local.go +++ b/pkg/services/object/put/local.go @@ -3,13 +3,20 @@ package putsvc import ( "fmt" - "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" "github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer" "github.com/nspcc-dev/neofs-sdk-go/object" + objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" ) +// ObjectStorage is an object storage interface. +type ObjectStorage interface { + // Put must save passed object + // and return any appeared error. + Put(o *objectSDK.Object) error +} + type localTarget struct { - storage *engine.StorageEngine + storage ObjectStorage obj *object.Object @@ -31,7 +38,7 @@ func (t *localTarget) Write(p []byte) (n int, err error) { } func (t *localTarget) Close() (*transformer.AccessIdentifiers, error) { - if err := engine.Put(t.storage, t.obj); err != nil { + if err := t.storage.Put(t.obj); err != nil { return nil, fmt.Errorf("(%T) could not put object to local storage: %w", t, err) } diff --git a/pkg/services/object/put/service.go b/pkg/services/object/put/service.go index 61794f30d..65a867068 100644 --- a/pkg/services/object/put/service.go +++ b/pkg/services/object/put/service.go @@ -7,7 +7,6 @@ import ( "github.com/nspcc-dev/neofs-node/pkg/core/container" "github.com/nspcc-dev/neofs-node/pkg/core/netmap" "github.com/nspcc-dev/neofs-node/pkg/core/object" - "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine" objutil "github.com/nspcc-dev/neofs-node/pkg/services/object/util" "github.com/nspcc-dev/neofs-node/pkg/util" "github.com/nspcc-dev/neofs-node/pkg/util/logger" @@ -37,7 +36,7 @@ type cfg struct { maxSizeSrc MaxSizeSource - localStore *engine.StorageEngine + localStore ObjectStorage cnrSrc container.Source @@ -99,7 +98,7 @@ func WithMaxSizeSource(v MaxSizeSource) Option { } } -func WithLocalStorage(v *engine.StorageEngine) Option { +func WithObjectStorage(v ObjectStorage) Option { return func(c *cfg) { c.localStore = v }