locodedb

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContinentUnknown is an undefined Continent value.
	ContinentUnknown = iota

	// ContinentEurope corresponds to Europe.
	ContinentEurope

	// ContinentAfrica corresponds to Africa.
	ContinentAfrica

	// ContinentNorthAmerica corresponds to North America.
	ContinentNorthAmerica

	// ContinentSouthAmerica corresponds to South America.
	ContinentSouthAmerica

	// ContinentAsia corresponds to Asia.
	ContinentAsia

	// ContinentAntarctica corresponds to Antarctica.
	ContinentAntarctica

	// ContinentOceania corresponds to Oceania.
	ContinentOceania
)

Variables

View Source
var ErrAirportNotFound = errors.New("airport not found")

ErrAirportNotFound is returned by AirportRecord readers when the required airport is not found.

View Source
var ErrCountryNotFound = errors.New("country not found")
View Source
var ErrSubDivNotFound = errors.New("subdivision not found")

Functions

func FillDatabase

func FillDatabase(table SourceTable, airports AirportDB, continents ContinentsDB, names NamesDB, db DB) error

FillDatabase generates the NeoFS location database based on the UN/LOCODE table.

Types

type AirportDB

type AirportDB interface {
	// Must return the record by UN/LOCODE table record.
	//
	// Must return ErrAirportNotFound if there is no
	// related airport in the database.
	Get(locode.Record) (*AirportRecord, error)
}

AirportDB is an interface of NeoFS airport database.

type AirportRecord

type AirportRecord struct {
	// Name of the country where airport is located.
	CountryName string

	// Geo point where airport is located.
	Point *Point
}

AirportRecord represents the entry in NeoFS airport database.

type Continent

type Continent uint8

Continent is an enumeration of Earth's continent.

func ContinentFromString

func ContinentFromString(str string) Continent

ContinentFromString returns Continent value corresponding to passed string representation.

func (*Continent) Is

func (c *Continent) Is(c2 Continent) bool

Is checks if c is the same continent as c2.

func (Continent) String

func (c Continent) String() string

type ContinentsDB

type ContinentsDB interface {
	// Must return continent of the geo point.
	PointContinent(*Point) (*Continent, error)
}

ContinentsDB is an interface of NeoFS continent database.

type CountryCode

type CountryCode locodecolumn.CountryCode

CountryCode represents country code for storage in the NeoFS location database.

func CountryCodeFromString

func CountryCodeFromString(s string) (*CountryCode, error)

CountryCodeFromString parses string UN/LOCODE country code and returns CountryCode.

func CountryFromColumn

func CountryFromColumn(cc *locodecolumn.CountryCode) (*CountryCode, error)

CountryFromColumn converts UN/LOCODE country code to CountryCode.

func (*CountryCode) String

func (c *CountryCode) String() string

type DB

type DB interface {
	// Must save the record by key in the database.
	Put(Key, Record) error

	// Must return the record by key from the database.
	Get(Key) (*Record, error)
}

DB is an interface of NeoFS location database.

type Key

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

Key represents the key in NeoFS location database.

func NewKey

func NewKey(lc locode.LOCODE) (*Key, error)

NewKey calculates Key from LOCODE.

func (*Key) CountryCode

func (k *Key) CountryCode() *CountryCode

CountryCode returns location's country code.

func (*Key) LocationCode

func (k *Key) LocationCode() *LocationCode

LocationCode returns location code.

type LocationCode

type LocationCode locodecolumn.LocationCode

LocationCode represents location code for storage in the NeoFS location database.

func LocationCodeFromString

func LocationCodeFromString(s string) (*LocationCode, error)

LocationCodeFromString parses string UN/LOCODE location code and returns LocationCode.

func LocationFromColumn

func LocationFromColumn(cc *locodecolumn.LocationCode) (*LocationCode, error)

LocationFromColumn converts UN/LOCODE country code to LocationCode.

func (*LocationCode) String

func (l *LocationCode) String() string

type NamesDB

type NamesDB interface {
	// Must resolve country code to country name.
	//
	// Must return ErrCountryNotFound if there is no
	// country with provided code.
	CountryName(*CountryCode) (string, error)

	// Must resolve (country code, subdivision code) to
	// subdivision name.
	//
	// Must return ErrSubDivNotFound if either country or
	// subdivision is not presented in database.
	SubDivName(*CountryCode, string) (string, error)
}

NamesDB is an interface of the NeoFS location namespace.

type Point

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

Point represents 2D geographic point.

func NewPoint

func NewPoint(lat, lng float64) *Point

NewPoint creates, initializes and returns new Point.

func PointFromCoordinates

func PointFromCoordinates(crd *locodecolumn.Coordinates) (*Point, error)

PointFromCoordinates converts UN/LOCODE coordinates to Point.

func (Point) Latitude

func (p Point) Latitude() float64

Latitude returns Point's latitude.

func (Point) Longitude

func (p Point) Longitude() float64

Longitude returns Point's longitude.

type Record

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

Record represents the entry in NeoFS location database.

func LocodeRecord

func LocodeRecord(db DB, sLocode string) (*Record, error)

LocodeRecord returns record from the NeoFS location database corresponding to string representation of UN/LOCODE.

func NewRecord

func NewRecord(r locode.Record) (*Record, error)

NewRecord calculates Record from UN/LOCODE table record.

func (*Record) Continent

func (r *Record) Continent() *Continent

Continent returns location continent.

func (*Record) CountryName

func (r *Record) CountryName() string

CountryName returns country name.

func (*Record) GeoPoint

func (r *Record) GeoPoint() *Point

GeoPoint returns geo point of the location.

func (*Record) LocationName

func (r *Record) LocationName() string

LocationName returns location name.

func (*Record) SetContinent

func (r *Record) SetContinent(c *Continent)

SetContinent sets location continent.

func (*Record) SetCountryName

func (r *Record) SetCountryName(name string)

SetCountryName sets country name.

func (*Record) SetGeoPoint

func (r *Record) SetGeoPoint(p *Point)

SetGeoPoint sets geo point of the location.

func (*Record) SetLocationName

func (r *Record) SetLocationName(name string)

SetLocationName sets location name.

func (*Record) SetSubDivCode

func (r *Record) SetSubDivCode(name string)

SetSubDivCode sets subdivision code.

func (*Record) SetSubDivName

func (r *Record) SetSubDivName(name string)

SetSubDivName sets subdivision name.

func (*Record) SubDivCode

func (r *Record) SubDivCode() string

SubDivCode returns subdivision code.

func (*Record) SubDivName

func (r *Record) SubDivName() string

SubDivName returns subdivision name.

type SourceTable

type SourceTable interface {
	// Must iterate over all entries of the table
	// and pass next entry to the handler.
	//
	// Must return handler's errors directly.
	IterateAll(func(locode.Record) error) error
}

SourceTable is an interface of the UN/LOCODE table.

Directories

Path Synopsis
continents

Jump to

Keyboard shortcuts

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