Browse Source

Add method "IsValidContinent".

pull/143/head
Joachim Bauch 3 months ago
parent
commit
ffb79c747c
No known key found for this signature in database GPG Key ID: 77C1D22D53E15F02
  1. 28
      geoip.go
  2. 10
      geoip_test.go

28
geoip.go

@ -239,3 +239,31 @@ func LookupContinents(country string) []string {
return continents
}
}
func IsValidContinent(continent string) bool {
switch continent {
case "AF":
// Africa
fallthrough
case "AN":
// Antartica
fallthrough
case "AS":
// Asia
fallthrough
case "EU":
// Europe
fallthrough
case "NA":
// North America
fallthrough
case "SA":
// South America
fallthrough
case "OC":
// Oceania
return true
default:
return false
}
}

10
geoip_test.go

@ -200,3 +200,13 @@ func TestGeoLookupFromFile(t *testing.T) {
testGeoLookupReader(t, reader)
}
func TestIsValidContinent(t *testing.T) {
for country, continents := range ContinentMap {
for _, continent := range continents {
if !IsValidContinent(continent) {
t.Errorf("Continent %s of country %s is not valid", continent, country)
}
}
}
}

Loading…
Cancel
Save