locodedb

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: GPL-3.0 Imports: 5 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 the 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 a country code for the storage in the NeoFS location database.

func CountryCodeFromString

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

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

func CountryFromColumn

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

CountryFromColumn converts a UN/LOCODE country code to a 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 the location's country code.

func (*Key) LocationCode

func (k *Key) LocationCode() *LocationCode

LocationCode returns the location code.

type LocationCode

type LocationCode locodecolumn.LocationCode

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

func LocationCodeFromString

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

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

func LocationFromColumn

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

LocationFromColumn converts a UN/LOCODE country code to a LocationCode.

func (*LocationCode) String

func (l *LocationCode) String() string

type NamesDB

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

	// Must resolve (country code, subdivision code) to
	// a 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 a 2D geographic point.

func NewPoint

func NewPoint(lat, lng float64) *Point

NewPoint creates, initializes and returns a new Point.

func PointFromCoordinates

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

PointFromCoordinates converts a UN/LOCODE coordinates to a Point.

func (Point) Latitude

func (p Point) Latitude() float64

Latitude returns the Point's latitude.

func (Point) Longitude

func (p Point) Longitude() float64

Longitude returns the 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 the record from the NeoFS location database corresponding to the string representation of UN/LOCODE.

func NewRecord

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

NewRecord calculates the Record from the UN/LOCODE table record.

func (*Record) Continent

func (r *Record) Continent() *Continent

Continent returns the location continent.

func (*Record) CountryName

func (r *Record) CountryName() string

CountryName returns the 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 the location name.

func (*Record) SetContinent

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

SetContinent sets the location continent.

func (*Record) SetCountryName

func (r *Record) SetCountryName(name string)

SetCountryName sets the 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 the location name.

func (*Record) SetSubDivCode

func (r *Record) SetSubDivCode(name string)

SetSubDivCode sets the subdivision code.

func (*Record) SetSubDivName

func (r *Record) SetSubDivName(name string)

SetSubDivName sets the subdivision name.

func (*Record) SubDivCode

func (r *Record) SubDivCode() string

SubDivCode returns the subdivision code.

func (*Record) SubDivName

func (r *Record) SubDivName() string

SubDivName returns the 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