Files
Denozordec f710847320
Publish telemt-api gateway Docker image / test (push) Successful in 25s
Publish telemt-api gateway Docker image / build-and-push (push) Successful in 2m1s
Refactor GeoIP data handling to ensure consistent coordinate propagation
- 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.
2026-03-30 15:31:26 +07:00

50 lines
1.3 KiB
Go

package aggregate
import (
"github.com/telemt/telemt-api/internal/geoip"
)
// EnrichUniqueIPsGeo fills country/city on each IP when lookup succeeds.
func EnrichUniqueIPsGeo(rows []UniqueIPsRow, g *geoip.Service) {
if g == nil || len(rows) == 0 {
return
}
for i := range rows {
for j := range rows[i].IPs {
ip := rows[i].IPs[j].IP
res, ok := g.Lookup(ip)
if !ok {
continue
}
if res.CountryCode != "" {
s := res.CountryCode
rows[i].IPs[j].CountryCode = &s
}
if res.CountryName != "" {
s := res.CountryName
rows[i].IPs[j].CountryName = &s
}
if res.CityName != "" {
s := res.CityName
rows[i].IPs[j].CityName = &s
}
// Заполняем координаты если GeoIP нашёл геоданные (страна/город),
// даже если координаты оказались 0.0 (иначе карта может быть пустой).
if res.CountryCode != "" || res.CountryName != "" || res.CityName != "" {
lat := res.Latitude
lon := res.Longitude
rows[i].IPs[j].Latitude = &lat
rows[i].IPs[j].Longitude = &lon
}
if res.ASN != 0 {
a := res.ASN
rows[i].IPs[j].ASN = &a
}
if res.ASOrg != "" {
o := res.ASOrg
rows[i].IPs[j].ASOrganization = &o
}
}
}
}