From a737a46988f773a81f82a287baffdda5f2d73f99 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 10 Feb 2021 23:54:27 +0300 Subject: [PATCH] [#362] ir/netmap: Use const keys to node attributes from the API lib Signed-off-by: Leonard Lyubich --- .../netmap/nodevalidation/locode/calls.go | 2 +- .../netmap/nodevalidation/locode/validator.go | 31 ++++++------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/pkg/innerring/processors/netmap/nodevalidation/locode/calls.go b/pkg/innerring/processors/netmap/nodevalidation/locode/calls.go index b060435c5..3c4ad6ea6 100644 --- a/pkg/innerring/processors/netmap/nodevalidation/locode/calls.go +++ b/pkg/innerring/processors/netmap/nodevalidation/locode/calls.go @@ -30,7 +30,7 @@ var errMissingRequiredAttr = errors.New("missing required attribute in DB record func (v *Validator) VerifyAndUpdate(n *netmap.NodeInfo) error { mAttr := uniqueAttributes(n.Attributes()) - attrLocode, ok := mAttr[attrKeyLocode] + attrLocode, ok := mAttr[netmap.AttrUNLOCODE] if !ok { return errMissingLocode } diff --git a/pkg/innerring/processors/netmap/nodevalidation/locode/validator.go b/pkg/innerring/processors/netmap/nodevalidation/locode/validator.go index e98d33d0a..6d930a176 100644 --- a/pkg/innerring/processors/netmap/nodevalidation/locode/validator.go +++ b/pkg/innerring/processors/netmap/nodevalidation/locode/validator.go @@ -1,5 +1,9 @@ package locode +import ( + "github.com/nspcc-dev/neofs-api-go/pkg/netmap" +) + // Prm groups the required parameters of the Validator's constructor. // // All values must comply with the requirements imposed on them. @@ -26,21 +30,6 @@ type Validator struct { mAttr map[string]attrDescriptor } -// TODO: define constants in API lib. -const ( - attrKeyLocode = "UN-LOCODE" - - attrKeyCountryCode = "CountryCode" - attrKeyCountry = "Country" - - attrKeyLocation = "Location" - - attrKeySubDivCode = "SubDivCode" - attrKeySubDiv = "SubDiv" - - attrKeyContinent = "Continent" -) - // New creates a new instance of the Validator. // // Panics if at least one value of the parameters is invalid. @@ -51,15 +40,15 @@ func New(prm Prm) *Validator { return &Validator{ db: prm.DB, mAttr: map[string]attrDescriptor{ - attrKeyCountryCode: {converter: countryCodeValue}, - attrKeyCountry: {converter: countryValue}, + netmap.AttrCountryCode: {converter: countryCodeValue}, + netmap.AttrCountry: {converter: countryValue}, - attrKeyLocation: {converter: locationValue}, + netmap.AttrLocation: {converter: locationValue}, - attrKeySubDivCode: {converter: subDivCodeValue, optional: true}, - attrKeySubDiv: {converter: subDivValue, optional: true}, + netmap.AttrSubDivCode: {converter: subDivCodeValue, optional: true}, + netmap.AttrSubDiv: {converter: subDivValue, optional: true}, - attrKeyContinent: {converter: continentValue}, + netmap.AttrContinent: {converter: continentValue}, }, } }