-
Notifications
You must be signed in to change notification settings - Fork 38
/
validator.go
54 lines (46 loc) · 1.51 KB
/
validator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package locode
import (
"github.com/nspcc-dev/neofs-sdk-go/netmap"
)
// Prm groups the required parameters of the Validator's constructor.
//
// All values must comply with the requirements imposed on them.
// Passing incorrect parameter values will result in constructor
// failure (error or panic depending on the implementation).
type Prm struct {
// NeoFS LOCODE database interface.
//
// Must not be nil.
DB DB
}
// Validator is a utility that verifies and updates
// node attributes associated with its geographical location
// (LOCODE).
//
// For correct operation, the Validator must be created
// using the constructor (New) based on the required parameters
// and optional components. After successful creation,
// the Validator is immediately ready to work through API.
type Validator struct {
db DB
mAttr map[string]attrDescriptor
}
// New creates a new instance of the Validator.
//
// Panics if at least one value of the parameters is invalid.
//
// The created Validator does not require additional
// initialization and is completely ready for work.
func New(prm Prm) *Validator {
return &Validator{
db: prm.DB,
mAttr: map[string]attrDescriptor{
netmap.AttrCountryCode: {converter: countryCodeValue},
netmap.AttrCountry: {converter: countryValue},
netmap.AttrLocation: {converter: locationValue},
netmap.AttrSubDivCode: {converter: subDivCodeValue, optional: true},
netmap.AttrSubDiv: {converter: subDivValue, optional: true},
netmap.AttrContinent: {converter: continentValue},
},
}
}