Add support for showing anycast addresses in the UI
This commit is contained in:
@@ -11,6 +11,14 @@ func (l *Location) AddCountryInfo() {
|
||||
return
|
||||
}
|
||||
|
||||
// Check for anycast.
|
||||
if l.IsAnycast {
|
||||
// Reset data for anycast.
|
||||
l.Country.Code = "__"
|
||||
l.Coordinates.Latitude = 0
|
||||
l.Coordinates.Longitude = 0
|
||||
}
|
||||
|
||||
// Get country info.
|
||||
info, ok := countries[l.Country.Code]
|
||||
if !ok {
|
||||
@@ -83,6 +91,10 @@ func init() {
|
||||
}
|
||||
|
||||
var countries = map[string]CountryInfo{
|
||||
"__": {
|
||||
Name: "Anycast",
|
||||
Center: Coordinates{AccuracyRadius: earthCircumferenceInKm},
|
||||
},
|
||||
"MN": {
|
||||
Name: "Mongolia",
|
||||
Continent: ContinentInfo{Region: "AS-E"},
|
||||
|
||||
@@ -9,6 +9,11 @@ func TestCountryInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for key, country := range countries {
|
||||
// Skip special anycast country.
|
||||
if key == "__" {
|
||||
continue
|
||||
}
|
||||
|
||||
if key != country.Code {
|
||||
t.Errorf("%s has a wrong country code of %q", key, country.Code)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user