https://github.com/ferdypruis/iso3166
ISO 3166-1 codes for the representation of countries
https://github.com/ferdypruis/iso3166
3166 countries country go golang iso iso3166 iso3166-1
Last synced: 5 months ago
JSON representation
ISO 3166-1 codes for the representation of countries
- Host: GitHub
- URL: https://github.com/ferdypruis/iso3166
- Owner: ferdypruis
- License: mit
- Created: 2020-01-16T20:53:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T06:57:25.000Z (over 3 years ago)
- Last Synced: 2024-09-22T09:18:40.278Z (over 1 year ago)
- Topics: 3166, countries, country, go, golang, iso, iso3166, iso3166-1
- Language: Go
- Homepage:
- Size: 30.3 KB
- Stars: 5
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# iso3166
[](https://godoc.org/github.com/ferdypruis/iso3166)
[](https://golangci.com/r/github.com/ferdypruis/iso3166)
A Go package providing all ISO 3166-1 country codes as constants of type `iso3166.Country`.
For each country the two-letter and three-letter alphabetic codes, the three-digit numeric code
and the English name are available.
Countries can either be hardcoded using the available constants or loaded from a string using `FromAlpha2()`,
`FromAlpha3()` and `FromNumeric()`.
## Examples
Use the constants to directly reference countries.
```go
fmt.Println("The numeric code for Antarctica is", iso3166.AQ.Numeric())
// Output:
// The numeric code for Antarctica is 010
```
Use `FromAlpha2()`, `FromAlpha3()` and `FromNumeric()` to load a country from a string.
```go
alpha2 := "NL"
country, _ := iso3166.FromAlpha2(alpha2) // Ignoring error for simplicity
fmt.Println("The three-letter code for", country.Name(), "is", country.Alpha3())
// Output:
// The three-letter code for Netherlands is NLD
```
Wrap in `Must()` to return a single value or panic on error;
```go
fmt.Println("The two-letter code for the United States is", iso3166.Must(iso3166.FromAlpha3("USA")).Alpha2())
// Output:
// The two-letter code for the United States is US
```
## Source
- [DataHub Core Data](https://datahub.io/core/country-codes)