Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more abbreviations for regions #13

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions pkg/regionmap/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ func GetRegion(ip netip.Addr, r ip2location.Record) (string, error) {
// 3-region model: https://en.wikipedia.org/wiki/List_of_regions_of_Canada @ 2022-11-20
switch r.Region {
case "British Columbia", "Alberta", "Saskatchewan", "Manitoba":
return "Canada West", nil
return "CA West", nil

case "Ontario", "Quebec", "New Brunswick", "Prince Edward Island",
"Nova Scotia", "Newfoundland and Labrador":
return "Canada East", nil
return "CA East", nil

case "Yukon", "Northwest Territories", "Nunavut":
return "Canada North", nil
return "CA North", nil

case "":
return "Canada", nil
return "CA", nil

default:
return "Canada", fmt.Errorf("unhandled Canada province %q", r.Region)
return "CA", fmt.Errorf("unhandled Canada province %q", r.Region)
}
}

Expand Down Expand Up @@ -87,14 +87,14 @@ func GetRegion(ip netip.Addr, r ip2location.Record) (string, error) {
}
}

// for China, use "China"
// for China, use "CN"
if r.CountryShort == "CN" {
return "China", nil
return "CN", nil
}

// for Russia, use "Russia"
// for Russia, use "RU"
if r.CountryShort == "RU" {
return "Russia", nil
return "RU", nil
}

// for Antartica, use Antartica (this won't really get hit in practice though)
Expand All @@ -118,10 +118,10 @@ func GetRegion(ip netip.Addr, r ip2location.Record) (string, error) {
return "Americas", nil
}

// group Oceania (Australia/NZ/Polynesia/Micronesia) into "Australia" since
// people may not recognize "Oceania"
// group Oceania (Australia/NZ/Polynesia/Micronesia) into "AUS" since people
// may not recognize "Oceania"
if m49region == "Oceania" {
return "Australia", nil
return "AUS", nil
}

// group Africa together to keep things neat (and there aren't really
Expand All @@ -134,15 +134,15 @@ func GetRegion(ip netip.Addr, r ip2location.Record) (string, error) {
if m49region == "Europe" {
switch m49subRegion {
case "Eastern Europe":
return "Europe East", nil
return "EU East", nil
case "Northern Europe":
return "Europe North", nil
return "EU North", nil
case "Southern Europe":
return "Europe South", nil
return "EU South", nil
case "Western Europe":
return "Europe West", nil
return "EU West", nil
default:
return "Europe", fmt.Errorf("unhandled M.49 %s sub-region %q", m49region, m49subRegion)
return "EU", fmt.Errorf("unhandled M.49 %s sub-region %q", m49region, m49subRegion)
}
}

Expand Down