[#316] locode: Define the API of location database

Define structure of keys and records of the location database. Define the
interfaces of all components necessary for the formation of the database.
Implement the function of filling the database.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-02-08 20:27:19 +03:00 committed by Leonard Lyubich
parent 0be35859ed
commit cdd1274e1c
6 changed files with 523 additions and 0 deletions

View file

@ -0,0 +1,81 @@
package locodedb
// Continent is an enumeration of Earth's continent.
type Continent uint8
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
)
// Is checks if c is the same continent as c2.
func (c *Continent) Is(c2 Continent) bool {
return *c == c2
}
func (c Continent) String() string {
switch c {
case ContinentUnknown:
fallthrough
default:
return "Unknown"
case ContinentEurope:
return "Europe"
case ContinentAfrica:
return "Africa"
case ContinentNorthAmerica:
return "North America"
case ContinentSouthAmerica:
return "South America"
case ContinentAsia:
return "Asia"
case ContinentAntarctica:
return "Antarctica"
case ContinentOceania:
return "Oceania"
}
}
// ContinentFromString returns Continent value
// corresponding to passed string representation.
func ContinentFromString(str string) Continent {
switch str {
default:
return ContinentUnknown
case "Europe":
return ContinentEurope
case "Africa":
return ContinentAfrica
case "North America":
return ContinentNorthAmerica
case "South America":
return ContinentSouthAmerica
case "Asia":
return ContinentAsia
case "Antarctica":
return ContinentAntarctica
case "Oceania":
return ContinentOceania
}
}