The country-continent
package provides a convenient way to retrieve information about countries and continents. It allows you to map country codes to country names and continents, as well as retrieve countries by continent.
- Get the full name of a country from its country code
- Get the full name and continent of a country from its country code
- Get the continent of a country from its country code
- Get a list of country codes belonging to a specific continent
To install the package, use the following command:
go get github.com/demoulin/countrycontinent@v1.5.0
func CountryGetFullName(countryCode string) string
Returns the full name of a country given its country code.
func CountryGetFullNameContinent(countryCode string) (string, string)
Returns the full name and continent of a country given its country code.
func CountryGetContinent(countryCode string) string
Returns the continent of a country given its country code.
func ContinentGetCountries(continent string) []string
Returns a list of country codes belonging to a given continent.
package main
import (
"fmt"
"github.com/demoulin/countrycontinent"
)
func main() {
// Get the full name of a country
fmt.Println(countrycontinent.CountryGetFullName("US")) // Output: "United States"
// Get the full name and continent of a country
name, continent := countrycontinent.CountryGetFullNameContinent("US")
fmt.Printf("Country: %s, Continent: %s\n", name, continent) // Output: Country: United States, Continent: North America
// Get the continent of a country
fmt.Println(countrycontinent.CountryGetContinent("US")) // Output: "North America"
// Get countries in a continent
countries := countrycontinent.ContinentGetCountries("Europe")
fmt.Println(countries) // Output: [AD AL AT BA BE BG BY CH CZ DE DK EE ES FI FO FR GB GI GR HR HU IE IS IT LI LT LU LV MC MD MK MT NL NO PL PT RO RU SE SI SJ SK SM UA VA YU]
}
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This package is licensed under the MIT License.
Forked from https://github.com/ArsFy/countrycontinent