Documentation ¶
Overview ¶
Package locodedb implements a UN LOCODE database.
It contains all the data internally and provides simple Get API to retrieve records based on short LOCODE strings. The DB is stored compressed before the first use (~1MB) and is unpacked automatically on the first access (which takes ~100-200ms). Unpacked it needs ~4MB of RAM.
Index ¶
Constants ¶
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 )
const CountryCodeLen = 2
CountryCodeLen is the length of the country code.
const LocationCodeLen = 3
LocationCodeLen is the length of the location code.
Variables ¶
var ErrInvalidString = errors.New("invalid string format in UN/Locode")
ErrInvalidString is returned when the string is not a valid location code.
var ErrNotFound = errors.New("record not found")
ErrNotFound is returned when the record is not found in the location database.
Functions ¶
This section is empty.
Types ¶
type Continent ¶
type Continent uint8
Continent is an enumeration of Earth's continent.
func ContinentFromString ¶
ContinentFromString returns Continent value corresponding to the passed string representation.
type CountryCode ¶
type CountryCode [CountryCodeLen]uint8
CountryCode represents ISO 3166 alpha-2 Country Code.
func CountryCodeFromString ¶
func CountryCodeFromString(s string) (*CountryCode, error)
CountryCodeFromString parses a string and returns the country code.
func (*CountryCode) String ¶
func (c *CountryCode) String() string
String returns a string representation of the country code.
func (*CountryCode) Symbols ¶
func (c *CountryCode) Symbols() [CountryCodeLen]uint8
Symbols returns the country code as a slice of symbols.
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key represents the key in location database. It contains the country code and the location code.
func NewKey ¶
NewKey returns a new Key from a country code and a location code string pair (e.g. "USNYC") or an error if the string is invalid. The country code must be 2 letters long and the location code 3 letters long.
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 [LocationCodeLen]uint8
LocationCode represents a location code for the storage in the location database.
func LocationCodeFromString ¶
func LocationCodeFromString(s string) (*LocationCode, error)
LocationCodeFromString parses a string and returns the location code.
func (*LocationCode) String ¶
func (l *LocationCode) String() string
String returns a string representation of the location code.
func (*LocationCode) Symbols ¶
func (l *LocationCode) Symbols() [LocationCodeLen]uint8
Symbols returns the location code as a slice of symbols.
type Record ¶
type Record struct { Country string Location string SubDivName string SubDivCode string Point Point Cont Continent }
Record represents a record in the location database (resulting CSV files). It contains all the information about the location. It is used to fill the database. Country, Location are full names, codes are in Key.