Documentation
¶
Index ¶
- Constants
- type CapitalInfo
- type Car
- type Country
- func All(fields ...string) ([]Country, error)
- func ByCapital(capital string, fields ...string) ([]Country, error)
- func ByCode(code string, fields ...string) (Country, error)
- func ByCodes(codes []string, fields ...string) ([]Country, error)
- func ByCurrency(currency string, fields ...string) ([]Country, error)
- func ByDemonym(demonym string, fields ...string) ([]Country, error)
- func ByFullName(name string, fields ...string) ([]Country, error)
- func ByIndependence(independent bool, fields ...string) ([]Country, error)
- func ByLanguage(language string, fields ...string) ([]Country, error)
- func ByName(name string, fields ...string) ([]Country, error)
- func ByRegion(region string, fields ...string) ([]Country, error)
- func BySubregion(subregion string, fields ...string) ([]Country, error)
- func ByTranslation(translation string, fields ...string) ([]Country, error)
- type Currency
- type Demonyms
- type ErrorMessage
- type Idd
- type Name
- type NativeNameT
- type PostalCode
Examples ¶
Constants ¶
const ApiVersion = "v3.1"
const BaseUrl = "https://restcountries.com/" + ApiVersion + "/"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CapitalInfo ¶
type CapitalInfo struct {
Latlng []float64 `json:"latlng"` // Capital latitude and longitude
}
CapitalInfo represents the capital information, specifically the latitude and longitude coordinates.
type Car ¶
type Car struct {
Signs []string `json:"signs"` // Car distinguished (oval) signs
Side string `json:"side"` // Car driving side
}
Car represents the driving side and distinguished (oval) signs of a country.
type Country ¶
type Country struct {
Name Name `json:"name"`
Tld []string `json:"tld"` // Internet top level domains
Cca2 string `json:"cca2"` // ISO 3166-1 alpha-2 two-letter country codes
Ccn3 string `json:"ccn3"` // ISO 3166-1 numeric code (UN M49)
Cca3 string `json:"cca3"` // ISO 3166-1 alpha-3 three-letter country codes
Cioc string `json:"cioc"` // Code of the International Olympic Committee
Fifa string `json:"fifa"` // FIFA code
Independent bool `json:"independent"` // ISO 3166-1 independence status (the country is considered a sovereign state)
Status string `json:"status"` // ISO 3166-1 assignment status
UnMember bool `json:"unMember"` // UN Member status
Currencies map[string]Currency `json:"currencies"` // List of all currencies
Idd Idd `json:"idd"` // International dialing codes
Capital []string `json:"capital"` // Capital cities
CapitalInfo CapitalInfo `json:"capitalInfo"` // Capital latitude and longitude
AltSpellings []string `json:"altSpellings"` // Alternate spellings of the country name
Region string `json:"region"` // UN demographic regions
Subregion string `json:"subregion"` // UN demographic subregions
Continents []string `json:"continents"` // List of continents the country is on
Languages map[string]string `json:"languages"` // List of official language
Translations map[string]Name `json:"translations"` // List of country name translations
Latlng []float64 `json:"latlng"` // Latitude and longitude
Landlocked bool `json:"landlocked"` // Landlocked country
Borders []string `json:"borders"` // Border countries
Area float64 `json:"area"` // Geographical size
Demonyms Demonyms `json:"demonyms"` // Inhabitants of the country
Flag string `json:"flag"` // flag emoji
Flags map[string]string `json:"flags"` // Flagpedia links to svg and png flags
CoatOfArms map[string]string `json:"coatOfArms"` // MainFacts.com links to svg and png images
Population int `json:"population"` // Country population
Maps map[string]string `json:"maps"` // Link to Google maps and Open Street maps
Gini map[string]float64 `json:"gini"` // Worldbank Gini index
Car Car `json:"car"` // Car driving side and distinguished (oval) signs
PostalCode PostalCode `json:"postalCode"` // Country postal codes
StartOfWeek string `json:"startOfWeek"` // Day of the start of week (Sunday/Monday/Saturday)
Timezones []string `json:"timezones"` // Timezones
}
Country represents the main structure for a country, including various details such as name, codes, currencies, languages, and more.
func All ¶
All retrieves data for all countries. You must specify the fields you need (up to 10 fields) when calling this method, otherwise you'll get an error.
func ByCode ¶
ByCode retrieves data for the country matching the given country code. You can use either cca2 (ISO 3166-1 alpha-2) ccn3 (ISO 3166-1 numeric), cca3 (ISO 3166-1 alpha-3) or cioc (International Olympic Committee)
func ByCodes ¶
ByCodes retrieves data for multiple countries matching the given country codes. You can use the same codes as in ByCode function. The codes should be provided as a slice of strings.
func ByCurrency ¶
ByCurrency retrieves data for countries using the given currency code or name.
func ByFullName ¶
ByFullName retrieves data for countries matching the exact full name. It can be the common or official name.
func ByIndependence ¶
ByIndependence retrieves data for countries based on their independence status.
func ByLanguage ¶
ByLanguage retrieves data for countries where the given language code or name is spoken.
func ByName ¶
ByName retrieves data for countries matching the given name. It can be the common or official name. If you want to get an exact match, use the ByFullName function.
Example ¶
countries, err := countries.ByName("Switzerland", "name", "capital", "region")
if err != nil {
panic(err)
}
for _, country := range countries {
fmt.Printf("The capital of %s (%s) is %s.\n", country.Name.Common, country.Region, country.Capital[0])
}
Output: The capital of Switzerland (Europe) is Bern.
func ByRegion ¶
ByRegion retrieves data for countries in the given region (e.g. Europe) Currently available regions are: Africa, Americas, Antarctic, Asia, Europe and Oceania.
func BySubregion ¶
BySubregion retrieves data for countries in the given subregion (e.g. Western Europe)
type Currency ¶
type Currency struct {
Name string `json:"name"` // Currency name
Symbol string `json:"symbol"` // Currency symbol
}
Currency represents the currency structure with its name and symbol.
type Demonyms ¶
Demonyms represents the name of the inhabitants, with separate fields for male and female forms.
type ErrorMessage ¶
type Idd ¶
type Idd struct {
Root string `json:"root"` // International direct dialing root
Suffixes []string `json:"suffixes"` // International direct dialing suffixes
}
Idd represents the international direct dialing information, including the root and suffixes.
type Name ¶
type Name struct {
NativeNameT
NativeName map[string]NativeNameT `json:"nativeName"` // Native country name
}
Name represents the name structure. It includes the native names, and a map of native names in different languages.
type NativeNameT ¶
type NativeNameT struct {
Official string `json:"official"` // Official country name
Common string `json:"common"` // Common country name
}
NativeNameT represents the native name structure
type PostalCode ¶
type PostalCode struct {
Format string `json:"format"` // Postal code format
Regex string `json:"regex"` // Postal code regex pattern
}
PostalCode represents the postal code format and regex pattern.