Add support for showing anycast addresses in the UI

This commit is contained in:
Daniel
2024-05-28 15:39:05 +02:00
parent 1381556e93
commit dc1b9f98f2
6 changed files with 24 additions and 2 deletions

View File

@@ -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"},

View File

@@ -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)
}