Stop crash with invalid/missing geoip data. Fixes #414
This commit is contained in:
parent
5b22b22308
commit
62d85a8b1d
@ -29,6 +29,14 @@ func GetGeoFromIP(ip string) *GeoDetails {
|
|||||||
return &cachedGeoDetails
|
return &cachedGeoDetails
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ip == "::1" || ip == "127.0.0.1" {
|
||||||
|
return &GeoDetails{
|
||||||
|
CountryCode: "N/A",
|
||||||
|
RegionName: "Localhost",
|
||||||
|
TimeZone: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,9 +80,16 @@ func FetchGeoForIP(ip string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var regionName = "Unknown"
|
||||||
|
if len(record.Subdivisions) > 0 {
|
||||||
|
if region, ok := record.Subdivisions[0].Names["en"]; ok {
|
||||||
|
regionName = region
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
response := GeoDetails{
|
response := GeoDetails{
|
||||||
CountryCode: record.Country.IsoCode,
|
CountryCode: record.Country.IsoCode,
|
||||||
RegionName: record.Subdivisions[0].Names["en"],
|
RegionName: regionName,
|
||||||
TimeZone: record.Location.TimeZone,
|
TimeZone: record.Location.TimeZone,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user