locode

package
v0.38.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	// Must find the record that corresponds to
	// LOCODE and provides the Record interface.
	//
	// Must return an error if Record is nil.
	//
	// LOCODE is always non-nil.
	Get(*locode.LOCODE) (Record, error)
}

DB is an interface of read-only FrostFS LOCODE database.

type Prm

type Prm struct {
	// FrostFS LOCODE database interface.
	//
	// Must not be nil.
	DB DB
}

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 Record

type Record interface {
	// Must return ISO 3166-1 alpha-2
	// country code.
	//
	// Must not return nil.
	CountryCode() *locodedb.CountryCode

	// Must return English short country name
	// officially used by the ISO 3166
	// Maintenance Agency (ISO 3166/MA).
	CountryName() string

	// Must return UN/LOCODE 3-character code
	// for the location (numerals 2-9 may also
	// be used).
	//
	// Must not return nil.
	LocationCode() *locodedb.LocationCode

	// Must return name of the location which
	// have been allocated a UN/LOCODE without
	// diacritic sign.
	LocationName() string

	// Must return ISO 1-3 character alphabetic
	// and/or numeric code for the administrative
	// division of the country concerned.
	SubDivCode() string

	// Must return subdivision name.
	SubDivName() string

	// Must return existing continent where is
	// the location.
	//
	// Must not return nil.
	Continent() *locodedb.Continent
}

Record is an interface of read-only FrostFS LOCODE database single entry.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

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.

func New

func New(prm Prm) *Validator

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 (*Validator) VerifyAndUpdate

func (v *Validator) VerifyAndUpdate(n *netmap.NodeInfo) error

VerifyAndUpdate validates UN-LOCODE attribute of n and adds a group of related attributes.

If n contains at least one of the LOCODE-derived attributes, an error is returned.

If n contains UN-LOCODE attribute and its value does not match the UN/LOCODE format, an error is returned.

New attributes are formed from the record of DB instance (Prm). If DB entry R was found w/o errors, new attributes are:

  • CountryCode: R.CountryCode().String();
  • Country: R.CountryName();
  • Location: Record.LocationName();
  • SubDivCode: R.SubDivCode();
  • SubDiv: R.SubDivName();
  • Continent: R.Continent().String().

UN-LOCODE attribute remains untouched.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL