mirror of https://github.com/mpolden/echoip
fixing the runtime error: index out of range [0] with length 0
This commit is contained in:
parent
35dcabb809
commit
ae769e61f9
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue