From 5321f8ef9c855a6a7737c4f3731469c89c6661af Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 14 Sep 2022 17:36:37 +0300 Subject: [PATCH] [#1786] engine: Unify parameter setters Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/engine/delete.go | 8 ++------ pkg/local_object_storage/engine/get.go | 4 +--- pkg/local_object_storage/engine/head.go | 8 ++------ pkg/local_object_storage/engine/inhume.go | 18 ++++++------------ pkg/local_object_storage/engine/put.go | 4 +--- pkg/local_object_storage/engine/range.go | 8 ++------ pkg/local_object_storage/engine/select.go | 8 ++------ 7 files changed, 16 insertions(+), 42 deletions(-) diff --git a/pkg/local_object_storage/engine/delete.go b/pkg/local_object_storage/engine/delete.go index 3cba830c4d..25dafd95a4 100644 --- a/pkg/local_object_storage/engine/delete.go +++ b/pkg/local_object_storage/engine/delete.go @@ -23,18 +23,14 @@ type DeleteRes struct{} // // Option is required. func (p *DeletePrm) WithAddress(addr oid.Address) { - if p != nil { - p.addr = addr - } + p.addr = addr } // WithForceRemoval is a Delete option to remove an object despite any // restrictions imposed on deleting that object. Expected to be used // only in control service. func (p *DeletePrm) WithForceRemoval() { - if p != nil { - p.forceRemoval = true - } + p.forceRemoval = true } // Delete marks the objects to be removed. diff --git a/pkg/local_object_storage/engine/get.go b/pkg/local_object_storage/engine/get.go index 809912cb86..3e7efce705 100644 --- a/pkg/local_object_storage/engine/get.go +++ b/pkg/local_object_storage/engine/get.go @@ -25,9 +25,7 @@ type GetRes struct { // // Option is required. func (p *GetPrm) WithAddress(addr oid.Address) { - if p != nil { - p.addr = addr - } + p.addr = addr } // Object returns the requested object. diff --git a/pkg/local_object_storage/engine/head.go b/pkg/local_object_storage/engine/head.go index eed783db1f..553ab41097 100644 --- a/pkg/local_object_storage/engine/head.go +++ b/pkg/local_object_storage/engine/head.go @@ -25,18 +25,14 @@ type HeadRes struct { // // Option is required. func (p *HeadPrm) WithAddress(addr oid.Address) { - if p != nil { - p.addr = addr - } + p.addr = addr } // WithRaw is a Head option to set raw flag value. If flag is unset, then Head // returns the header of the virtual object, otherwise it returns SplitInfo of the virtual // object. func (p *HeadPrm) WithRaw(raw bool) { - if p != nil { - p.raw = raw - } + p.raw = raw } // Header returns the requested object header. diff --git a/pkg/local_object_storage/engine/inhume.go b/pkg/local_object_storage/engine/inhume.go index 35f4ef9843..9a88dd055e 100644 --- a/pkg/local_object_storage/engine/inhume.go +++ b/pkg/local_object_storage/engine/inhume.go @@ -28,29 +28,23 @@ type InhumeRes struct{} // tombstone should not be nil, addr should not be empty. // Should not be called along with MarkAsGarbage. func (p *InhumePrm) WithTarget(tombstone oid.Address, addrs ...oid.Address) { - if p != nil { - p.addrs = addrs - p.tombstone = &tombstone - } + p.addrs = addrs + p.tombstone = &tombstone } // MarkAsGarbage marks an object to be physically removed from local storage. // // Should not be called along with WithTarget. func (p *InhumePrm) MarkAsGarbage(addrs ...oid.Address) { - if p != nil { - p.addrs = addrs - p.tombstone = nil - } + p.addrs = addrs + p.tombstone = nil } // WithForceRemoval inhumes objects specified via MarkAsGarbage with GC mark // without any object restrictions checks. func (p *InhumePrm) WithForceRemoval() { - if p != nil { - p.forceRemoval = true - p.tombstone = nil - } + p.forceRemoval = true + p.tombstone = nil } var errInhumeFailure = errors.New("inhume operation failed") diff --git a/pkg/local_object_storage/engine/put.go b/pkg/local_object_storage/engine/put.go index 613a4eb5ff..f6f98f55e3 100644 --- a/pkg/local_object_storage/engine/put.go +++ b/pkg/local_object_storage/engine/put.go @@ -23,9 +23,7 @@ var errPutShard = errors.New("could not put object to any shard") // // Option is required. func (p *PutPrm) WithObject(obj *objectSDK.Object) { - if p != nil { - p.obj = obj - } + p.obj = obj } // Put saves the object to local storage. diff --git a/pkg/local_object_storage/engine/range.go b/pkg/local_object_storage/engine/range.go index 554fc9850b..1694d895c3 100644 --- a/pkg/local_object_storage/engine/range.go +++ b/pkg/local_object_storage/engine/range.go @@ -27,9 +27,7 @@ type RngRes struct { // // Option is required. func (p *RngPrm) WithAddress(addr oid.Address) { - if p != nil { - p.addr = addr - } + p.addr = addr } // WithPayloadRange is a GetRange option to set range of requested payload data. @@ -37,9 +35,7 @@ func (p *RngPrm) WithAddress(addr oid.Address) { // Missing an option or calling with zero length is equivalent // to getting the full payload range. func (p *RngPrm) WithPayloadRange(rng *objectSDK.Range) { - if p != nil { - p.off, p.ln = rng.GetOffset(), rng.GetLength() - } + p.off, p.ln = rng.GetOffset(), rng.GetLength() } // Object returns the requested object part. diff --git a/pkg/local_object_storage/engine/select.go b/pkg/local_object_storage/engine/select.go index 063a5c4b6e..0e5a8ca227 100644 --- a/pkg/local_object_storage/engine/select.go +++ b/pkg/local_object_storage/engine/select.go @@ -20,16 +20,12 @@ type SelectRes struct { // WithContainerID is a Select option to set the container id to search in. func (p *SelectPrm) WithContainerID(cnr cid.ID) { - if p != nil { - p.cnr = cnr - } + p.cnr = cnr } // WithFilters is a Select option to set the object filters. func (p *SelectPrm) WithFilters(fs object.SearchFilters) { - if p != nil { - p.filters = fs - } + p.filters = fs } // AddressList returns list of addresses of the selected objects.