Documentation
¶
Index ¶
- Variables
- type Bounds
- type Coord
- type Country
- func (c *Country) EmojiFlag() string
- func (c *Country) FormatAddress(recipient, street, postalCode, city, region string) string
- func (c *Country) GDPRCompliant() bool
- func (c *Country) HasPostalCode() bool
- func (c *Country) MatchPostalCode(postalCode string) bool
- func (c *Country) Subdivision(code string) Subdivision
- func (c *Country) SubdivisionByName(name string) Subdivision
- type Geo
- type Subdivision
- type VatRates
Examples ¶
- Country.EmojiFlag
- Country.FormatAddress
- Country.GDPRCompliant
- Country.Subdivision
- Country.SubdivisionByName
- Get
- Get (ReadmeBoundaryBoxes)
- Get (ReadmeCountryFinders)
- Get (ReadmeEuropeanEconomicAreaMembership)
- Get (ReadmeEuropeanSingleMarketMembership)
- Get (ReadmeEuropeanUnionMembership)
- Get (ReadmeFormattedAddresses)
- Get (ReadmeIdentificationCodes)
- Get (ReadmeLocations)
- Get (ReadmeNamesAndTranslations)
- Get (ReadmeSubdivisions)
- Get (ReadmeTelephoneRouting)
- Get (ReadmeTimezones)
- Get (ReadmeVATRates)
Constants ¶
This section is empty.
Variables ¶
var All = []Country{}/* 249 elements not displayed */
All is a slice with all countries ordered by alpha2 code.
var Alpha2 = []string{} /* 249 elements not displayed */
Alpha2 is a slice with all country alpha2 codes.
var Regions = []string{"Africa", "Americas", "Asia", "Europe", "Oceania"}
Regions is a slice with all region names.
var Subregions = []string{"Australia and New Zealand", "Caribbean", "Central America", "Central Asia", "Eastern Africa", "Eastern Asia", "Eastern Europe", "Melanesia", "Micronesia", "Middle Africa", "Northern Africa", "Northern America", "Northern Europe", "Polynesia", "South America", "South-Eastern Asia", "Southern Africa", "Southern Asia", "Southern Europe", "Western Africa", "Western Asia", "Western Europe"}
Subregions is a slice with all subregion names.
Functions ¶
This section is empty.
Types ¶
type Bounds ¶
Bounds represents a country bounds: the northeast and the southwest geographic coordinates.
type Country ¶
type Country struct { AddressFormat string `yaml:"address_format"` Alpha2 string `yaml:"alpha2"` Alpha3 string `yaml:"alpha3"` Capital string `yaml:"capital"` Continent string `yaml:"continent"` CountryCode string `yaml:"country_code"` CurrencyCode string `yaml:"currency_code"` EEAMember bool `yaml:"eea_member"` EUMember bool `yaml:"eu_member"` G7Member bool `yaml:"g7_member"` G20Member bool `yaml:"g20_member"` ESMMember bool `yaml:"esm_member"` GEC string `yaml:"gec"` Geo Geo `yaml:"geo"` InternationalPrefix string `yaml:"international_prefix"` IOC string `yaml:"ioc"` ISOLongName string `yaml:"iso_long_name"` ISOShortName string `yaml:"iso_short_name"` LanguagesOfficial []string `yaml:"languages_official"` LanguagesSpoken []string `yaml:"languages_spoken"` NationalDestinationCodeLengths []int `yaml:"national_destination_code_lengths"` NationalNumberLengths []int `yaml:"national_number_lengths"` NationalPrefix string `yaml:"national_prefix"` Nationality string `yaml:"nationality"` Number string `yaml:"number"` PostalCodeFormat string `yaml:"postal_code_format"` Region string `yaml:"region"` StartOfWeek string `yaml:"start_of_week"` Subdivisions map[string]Subdivision `yaml:"-"` Subregion string `yaml:"subregion"` Timezones []string `yaml:"-"` Translations map[string]string `yaml:"-"` UnLocode string `yaml:"un_locode"` UnofficialNames []string `yaml:"unofficial_names"` VatRates VatRates `yaml:"vat_rates"` WorldRegion string `yaml:"world_region"` }
Country store all information about a country.
func Get ¶
Get returns the country identified by alpha2 code.
Example ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("US") fmt.Println(c.ISOShortName) }
Output: United States of America
Example (ReadmeBoundaryBoxes) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("US") fmt.Println(c.Geo.MinLatitude) fmt.Println(c.Geo.MaxLatitude) fmt.Println(c.Geo.MinLongitude) fmt.Println(c.Geo.MaxLongitude) fmt.Println(c.Geo.Bounds.Northeast.Lat) fmt.Println(c.Geo.Bounds.Northeast.Lng) fmt.Println(c.Geo.Bounds.Southwest.Lat) fmt.Println(c.Geo.Bounds.Southwest.Lng) }
Output: 18.91619 71.3577635769 -171.791110603 -66.96466 71.3577635769 -66.96466 18.91619 -171.791110603
Example (ReadmeCountryFinders) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { allCountries := countries.All countriesInEurope := countries.InRegion("Europe") countriesInSouthernAsia := countries.InSubregion("Southern Asia") countriesInEU := countries.InEU() fmt.Println(len(allCountries)) fmt.Println(len(countriesInEurope)) fmt.Println(len(countriesInSouthernAsia)) fmt.Println(len(countriesInEU)) }
Output: 249 51 9 34
Example (ReadmeEuropeanEconomicAreaMembership) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("FR") fmt.Println(c.EEAMember) }
Output: true
Example (ReadmeEuropeanSingleMarketMembership) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("CH") fmt.Println(c.ESMMember) }
Output: true
Example (ReadmeEuropeanUnionMembership) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("IT") fmt.Println(c.EUMember) }
Output: true
Example (ReadmeFormattedAddresses) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("US") fmt.Println(c.AddressFormat) fmt.Println("---") fmt.Println(c.FormatAddress("John Smith", "1084 Nuzum Court", "14214", "Buffalo", "New York")) }
Output: {{recipient}} {{street}} {{city}} {{region_short}} {{postalcode}} {{country}} --- John Smith 1084 Nuzum Court Buffalo NY 14214 United States of America
Example (ReadmeIdentificationCodes) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("US") fmt.Println(c.Number) fmt.Println(c.Alpha2) fmt.Println(c.Alpha3) fmt.Println(c.GEC) }
Output: 840 US USA US
Example (ReadmeLocations) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("US") fmt.Println(c.Geo.Latitude) fmt.Println(c.Geo.Longitude) fmt.Println(c.Region) fmt.Println(c.Subregion) fmt.Println(c.Continent) fmt.Println(c.WorldRegion) }
Output: 37.09024 -95.712891 Americas Northern America North America AMER
Example (ReadmeNamesAndTranslations) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("US") fmt.Println(c.ISOLongName) fmt.Println(c.ISOShortName) fmt.Println(c.UnofficialNames) fmt.Println(c.Translations["en"]) fmt.Println(c.Translations["it"]) fmt.Println(c.Translations["de"]) fmt.Println(c.Nationality) fmt.Println(c.Capital) fmt.Println(c.EmojiFlag()) }
Output: The United States of America United States of America [United States USA Vereinigte Staaten von Amerika États-Unis Estados Unidos アメリカ合衆国 Verenigde Staten Соединенные Штаты Америки] United States Stati Uniti Vereinigte Staaten American Washington 🇺🇸
Example (ReadmeSubdivisions) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("US") ca := c.Subdivision("CA") tx := c.SubdivisionByName("Texas") fmt.Println(len(c.Subdivisions)) fmt.Println(ca.Name) fmt.Println(ca.Type) fmt.Println(ca.Translations["de"]) fmt.Println(ca.Geo.Latitude) fmt.Println(tx.Code) }
Output: 57 California state Kalifornien 36.778261 TX
Example (ReadmeTelephoneRouting) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("US") fmt.Println(c.CountryCode) fmt.Println(c.NationalDestinationCodeLengths) fmt.Println(c.NationalNumberLengths) fmt.Println(c.InternationalPrefix) fmt.Println(c.NationalPrefix) }
Output: 1 [3] [10] 011 1
Example (ReadmeTimezones) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("DE") fmt.Println(c.Timezones) }
Output: [Europe/Berlin Europe/Busingen]
Example (ReadmeVATRates) ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("IE") fmt.Println(c.VatRates.Standard) fmt.Println(c.VatRates.Reduced) fmt.Println(c.VatRates.SuperReduced) fmt.Println(c.VatRates.Parking) }
Output: 23 [9 13] 4 13
func InEU ¶
func InEU() []Country
InEU returns all countries that are members of the European Union.
func InSubregion ¶
InSubregion returns all countries that are part of the subregion.
func (*Country) EmojiFlag ¶
EmojiFlag returns the country Emoji flag.
Example ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("US") fmt.Println(c.EmojiFlag()) }
Output: 🇺🇸
func (*Country) FormatAddress ¶
FormatAddress returns the formatted address based on country.AddressFormat template.
Example ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("US") fmt.Println(c.FormatAddress("John Smith", "1084 Nuzum Court", "14214", "Buffalo", "New York")) }
Output: John Smith 1084 Nuzum Court Buffalo NY 14214 United States of America
func (*Country) GDPRCompliant ¶ added in v0.2.0
GDPRCompliant returns true if the country is GDPR (General Data Protection Regulation) compliant. A country is GDPR compliant if is a member of the European Economic Area or it is UK.
Example ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("IT") fmt.Println(c.GDPRCompliant()) }
Output: true
func (*Country) HasPostalCode ¶
HasPostalCode determines whether the country has postal codes. It returns true if the country has postal codes, and false if it does not.
func (*Country) MatchPostalCode ¶
MatchPostalCode returns true if postalCode has a valid format for the country. If the country does not have a postal code, returns false.
func (*Country) Subdivision ¶
func (c *Country) Subdivision(code string) Subdivision
Subdivision returns the country's subdivision identified by code. If the code is not valid or not found returns a zero value Subdivision.
Example ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("US") ca := c.Subdivision("CA") fmt.Println(ca.Name) }
Output: California
func (*Country) SubdivisionByName ¶
func (c *Country) SubdivisionByName(name string) Subdivision
SubdivisionByName returns the country's subdivision with name name. If the name is not valid or not found returns a zero value Subdivision.
Example ¶
package main import ( "fmt" "github.com/pioz/countries" ) func main() { c := countries.Get("US") ca := c.SubdivisionByName("Texas") fmt.Println(ca.Code) }
Output: TX
type Geo ¶
type Geo struct { Latitude float64 `yaml:"latitude"` Longitude float64 `yaml:"longitude"` MaxLatitude float64 `yaml:"max_latitude"` MaxLongitude float64 `yaml:"max_longitude"` MinLatitude float64 `yaml:"min_latitude"` MinLongitude float64 `yaml:"min_longitude"` Bounds Bounds `yaml:"bounds"` }
Bounds store geographic informations of a country.
type Subdivision ¶
type Subdivision struct { Name string `yaml:"name"` Code string `yaml:"code"` Type string `yaml:"type"` Capital bool `yaml:"capital"` Geo Geo `yaml:"geo"` Translations map[string]string `yaml:"translations"` }
Subdivision store information about a subdivision like a region or a province or a state or a metropolitan city of a country.