Documentation ¶
Index ¶
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func CalculateHaversine(lat1, lon1, lat2, lon2 float64) (d float64)
- func CalculatePythagorasEquirectangular(lat1, lon1, lat2, lon2 float64) (d float64)
- func Deg2Rad(deg float64) float64
- func MeasureDistanceHaversine(m1 Measurer, m2 Measurer) (distance float64)
- func MeasureDistancePythagoras(m1 Measurer, m2 Measurer) (distance float64)
- func MustAsset(name string) []byte
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- type BaseLang
- type Codes
- type Coordinates
- type Country
- type Geo
- type Measurer
- type Query
- type SubDivision
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func CalculateHaversine ¶
Example ¶
se, _ := query.FindCountryByAlpha("SWE") de, _ := query.FindCountryByAlpha("DEU") distance := MeasureDistanceHaversine(se, de) fmt.Println(distance) distance = CalculateHaversine( se.Coordinates.MaxLatitude, se.Coordinates.MaxLongitude, de.Coordinates.MinLatitude, de.Coordinates.MinLongitude) fmt.Println(distance)
Output: 1430.1937864547901 2641.26145088825
func CalculatePythagorasEquirectangular ¶
Example ¶
se, _ := query.FindCountryByAlpha("SWE") de, _ := query.FindCountryByAlpha("DEU") distance := MeasureDistancePythagoras(se, de) fmt.Println(distance) distance = CalculatePythagorasEquirectangular( se.Coordinates.MaxLatitude, se.Coordinates.MaxLongitude, de.Coordinates.MinLatitude, de.Coordinates.MinLongitude) fmt.Println(distance)
Output: 1430.5502701671583 2667.2283097795016
func MeasureDistanceHaversine ¶
MeasureDistanceHaversine measures distances betweeen two countries using Havesine equation
func MeasureDistancePythagoras ¶
MeasureDistancePythagoras measures distances betweeen two countries using Pythagoras equirect angular equation
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
Types ¶
type Codes ¶
type Codes struct { Alpha2 string `json:"cca2"` Alpha3 string `json:"cca3"` CIOC string CCN3 string //CountryCode string // Yaml CallingCodes []string `json:"callingCode"` InternationalPrefix string // Yaml }
Codes contains various code representations
type Coordinates ¶
type Coordinates struct { LongitudeString string `json:"longitude"` LatitudeString string `json:"latitude"` MinLongitude float64 MinLatitude float64 MaxLongitude float64 MaxLatitude float64 Latitude float64 Longitude float64 }
Coordinates contains the coordinates for both Country and SubDivision
type Country ¶
type Country struct { Name struct { BaseLang `yaml:",inline"` Native map[string]BaseLang } `json:"name"` EuMember bool LandLocked bool Nationality string TLDs []string `json:"tld"` Languages map[string]string Translations map[string]BaseLang Currencies []string `json:"currency"` Borders []string // Grouped meta Codes Geo Coordinates // contains filtered or unexported fields }
Country contains all countries and their country codes
func (*Country) BorderingCountries ¶
BorderingCountries returns the bordering countries the given Country
func (Country) MeasurableCoordinates ¶
MeasurableCoordinates provides long/lat for country struct it does not store a pointer receiver to Country, as it needs to implement the Measurer interface
func (*Country) SubDivisions ¶
func (c *Country) SubDivisions() (subdivisions []SubDivision)
SubDivisions returns the subdivisions for the given Country
type Geo ¶
type Geo struct { Region string `json:"region"` SubRegion string `json:"subregion"` Continent string // Yaml Capital string `json:"capital"` Area float64 }
Geo contains geographical information
type Measurer ¶
type Measurer interface {
MeasurableCoordinates() (lat, long float64)
}
Measurer provides coordinates for measurements
type Query ¶
type Query struct { Countries map[string]Country Subdivisions map[string][]SubDivision NameToAlpha2 map[string]string Alpha3ToAlpha2 map[string]string }
Query contains queries for countries, cities, etc.
func NewFromPath ¶
NewFromPath creates a Query object from data folder in provided path
func (*Query) FindAllCountries ¶
FindAllCountries returns a list of all countries
func (Query) FindCountries ¶
FindCountries finds a Country based on the given struct data
func (*Query) FindCountryByAlpha ¶
FindCountryByAlpha fincs a country by given code
type SubDivision ¶
type SubDivision struct { Name string Names []string Code string CountryAlpha2 string Coordinates }
SubDivision contains Country subdivison information
func (*SubDivision) MeasurableCoordinates ¶
func (sd *SubDivision) MeasurableCoordinates() (lat, long float64)
MeasurableCoordinates provides long/lat for country struct