Documentation ¶
Index ¶
- func Asset(name string) ([]byte, error)
- func AssetDigest(name string) ([sha256.Size]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func AssetString(name string) (string, error)
- func CalculateHaversine(lat1, lon1, lat2, lon2 float64) (d float64)
- func CalculatePythagorasEquirectangular(lat1, lon1, lat2, lon2 float64) (d float64)
- func Deg2Rad(deg float64) float64
- func Digests() (map[string][sha256.Size]byte, error)
- func MeasureDistanceHaversine(m1 Measurer, m2 Measurer) (distance float64)
- func MeasureDistancePythagoras(m1 Measurer, m2 Measurer) (distance float64)
- func MustAsset(name string) []byte
- func MustAssetString(name string) string
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- type BaseLang
- type Codes
- type Coordinates
- type Country
- func (c *Country) BorderingCountries() (countries []Country)
- func (c *Country) FindSubdivisionByCode(code string) (result SubDivision, err error)
- func (c *Country) FindSubdivisionByName(name string) (result SubDivision, err error)
- func (c Country) MeasurableCoordinates() (lat, long float64)
- func (c *Country) SubDivisions() (subdivisions []SubDivision)
- type Geo
- type Measurer
- type Query
- func (q *Query) FindAllCountries() (countries map[string]Country)
- func (q Query) FindCountries(c Country) (countries []Country)
- func (q *Query) FindCountriesByCurrency(currency string) (results []Country, err error)
- func (q *Query) FindCountryByAlpha(code string) (result Country, err error)
- func (q *Query) FindCountryByCallingCode(callingCode string) (result Country, err error)
- func (q *Query) FindCountryByName(name string) (result Country, err error)
- func (q *Query) FindCountryByNativeName(name string) (result Country, err error)
- func (q *Query) FindSubdivisionCountryByName(subdivisionName string) (result Country, err error)
- 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 AssetDigest ¶
AssetDigest returns the digest of the file with the given name. It returns an error if the asset could not be found or the digest 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, and 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 AssetString ¶
AssetString returns the asset contents as a string (instead of a []byte).
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 MustAssetString ¶
MustAssetString is like AssetString 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) FindSubdivisionByCode ¶
func (c *Country) FindSubdivisionByCode(code string) (result SubDivision, err error)
FindSubdivisionByCode fincs a country by given code
func (*Country) FindSubdivisionByName ¶
func (c *Country) FindSubdivisionByName(name string) (result SubDivision, err error)
FindSubdivisionByName fincs a country by given name
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 NameToAlpha2 map[string]string Alpha3ToAlpha2 map[string]string NativeNameToAlpha2 map[string]string CallingCodeToAlpha2 map[string]string CurrencyToAlpha2 map[string][]Country }
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) FindCountriesByCurrency ¶ added in v0.1.6
FindCountriesByCurrency finds a Country based on the given struct data
func (*Query) FindCountryByAlpha ¶
FindCountryByAlpha fincs a country by given code
func (*Query) FindCountryByCallingCode ¶ added in v0.1.6
func (*Query) FindCountryByName ¶
FindCountryByName finds a country by given name
func (*Query) FindCountryByNativeName ¶
FindCountryByNativeName
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