-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter.go
26 lines (20 loc) · 924 Bytes
/
adapter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package geo
import "github.com/biter777/countries"
const UnknownAlpha2Code = "ZZ" // ZZ is the commonly recognized country/continent code for unknown, as specified in ISO alpha2
const UnknownAlpha3Code = "ZZZ" // ZZZ is derived from "ZZ" to represent 3 letter country/continent code for unknown, as specified in ISO alpha3
// CountryAlpha2CodeToAlpha3Code - get a 3-letter country code if a country identified by 2-letter country code
func CountryAlpha2CodeToAlpha3Code(alpha2Code string) string {
alpha3 := countries.ByName(alpha2Code).Alpha3()
if alpha3 == "Unknown" {
return UnknownAlpha3Code
}
return alpha3
}
// CountryAlpha3CodeToAlpha2Code - get a 2-letter country code if a country identified by 3-letter country code
func CountryAlpha3CodeToAlpha2Code(alpha3Code string) string {
alpha2 := countries.ByName(alpha3Code).Alpha2()
if alpha2 == "Unknown" {
return UnknownAlpha2Code
}
return alpha2
}