Refactor GeoIP data handling to ensure consistent coordinate propagation
Publish telemt-api gateway Docker image / test (push) Successful in 25s
Publish telemt-api gateway Docker image / build-and-push (push) Successful in 2m1s

- Updated the logic in the geo enrichment process to fill in geographic coordinates even when they are 0.0, enhancing map visualization.
- Modified the GeoIP lookup function to always return latitude and longitude, improving the accuracy of location data for the UI.
- Improved comments for clarity regarding the importance of geographic data in the mapping context.
This commit is contained in:
Denozordec
2026-03-30 15:31:26 +07:00
parent 452ee4f6f1
commit f710847320
2 changed files with 8 additions and 8 deletions
+3 -1
View File
@@ -28,7 +28,9 @@ func EnrichUniqueIPsGeo(rows []UniqueIPsRow, g *geoip.Service) {
s := res.CityName
rows[i].IPs[j].CityName = &s
}
if res.Latitude != 0 || res.Longitude != 0 {
// Заполняем координаты если GeoIP нашёл геоданные (страна/город),
// даже если координаты оказались 0.0 (иначе карта может быть пустой).
if res.CountryCode != "" || res.CountryName != "" || res.CityName != "" {
lat := res.Latitude
lon := res.Longitude
rows[i].IPs[j].Latitude = &lat
+5 -7
View File
@@ -101,13 +101,11 @@ func (s *Service) Lookup(ipStr string) (Result, bool) {
if rec.City.Names != nil {
out.CityName = rec.City.Names["en"]
}
// Coordinates are used by the UI map.
// Note: MaxMind might still return 0/0 for unknown locations.
if rec.Location.Latitude != 0 || rec.Location.Longitude != 0 {
out.Latitude = rec.Location.Latitude
out.Longitude = rec.Location.Longitude
ok = true
}
// Для карты важны координаты. Даже если MaxMind вернул (0,0),
// лучше прокидывать их дальше, чем скрывать все точки.
out.Latitude = rec.Location.Latitude
out.Longitude = rec.Location.Longitude
if out.CountryCode != "" || out.CountryName != "" || out.CityName != "" {
ok = true
}