[#362] ir/netmap: Use const keys to node attributes from the API lib

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-02-10 23:54:27 +03:00 committed by Leonard Lyubich
parent 34248b00ed
commit a737a46988
2 changed files with 11 additions and 22 deletions

View file

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

View file

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