Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1.45 KB

README.md

File metadata and controls

41 lines (31 loc) · 1.45 KB

iso3166

GoDoc GolangCI

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.

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.

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;

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