fixing the runtime error: index out of range [0] with length 0

This commit is contained in:
Dmitriy Shelikhov 2020-03-27 19:57:22 +07:00
parent 35dcabb809
commit ae769e61f9
1 changed files with 8 additions and 6 deletions

View File

@ -106,12 +106,14 @@ func (g *geoip) City(ip net.IP) (City, error) {
if c, exists := record.City.Names["en"]; exists {
city.Name = c
}
if c, exists := record.Subdivisions[0].Names["en"]; exists {
city.RegionName = c
}
if record.Subdivisions[0].IsoCode != "" {
city.RegionCode = record.Subdivisions[0].IsoCode
}
if len(record.Subdivisions)>0 {
if c, exists := record.Subdivisions[0].Names["en"]; exists {
city.RegionName = c
}
if record.Subdivisions[0].IsoCode != "" {
city.RegionCode = record.Subdivisions[0].IsoCode
}
}
if !math.IsNaN(record.Location.Latitude) {
city.Latitude = record.Location.Latitude
}