cleanup unnecessary codes
This commit is contained in:
parent
374c2b74ad
commit
8aeed47955
1 changed files with 7 additions and 18 deletions
25
geoip.go
25
geoip.go
|
|
@ -104,28 +104,17 @@ func geohashAndLocationFromMaxMindDb(address string) (string, string, string, er
|
||||||
return "s000", "Unknown", "Unknown", err
|
return "s000", "Unknown", "Unknown", err
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
countryName := "Unknown"
|
|
||||||
cityName := "Unknown"
|
|
||||||
var latitude, longitude float64
|
|
||||||
var iso string
|
|
||||||
// If you are using strings that may be invalid, check that ip is not nil
|
// If you are using strings that may be invalid, check that ip is not nil
|
||||||
ip := net.ParseIP(address)
|
ip := net.ParseIP(address)
|
||||||
cityRecord, err := db.City(ip)
|
cityRecord, err := db.City(ip)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
countryName = cityRecord.Country.Names["en"]
|
return "s000", "Unknown", "Unknown", err
|
||||||
cityName = cityRecord.City.Names["en"]
|
|
||||||
latitude = cityRecord.Location.Latitude
|
|
||||||
longitude = cityRecord.Location.Longitude
|
|
||||||
iso = cityRecord.Country.IsoCode
|
|
||||||
} else {
|
|
||||||
countryRecord, err := db.Country(ip)
|
|
||||||
if err != nil {
|
|
||||||
return "s000", countryName, cityName, err
|
|
||||||
}
|
|
||||||
countryName = countryRecord.Country.Names["en"]
|
|
||||||
cityName = "Unknown"
|
|
||||||
iso = countryRecord.Country.IsoCode
|
|
||||||
}
|
}
|
||||||
|
countryName := cityRecord.Country.Names["en"]
|
||||||
|
cityName := cityRecord.City.Names["en"]
|
||||||
|
latitude := cityRecord.Location.Latitude
|
||||||
|
longitude := cityRecord.Location.Longitude
|
||||||
|
iso := cityRecord.Country.IsoCode
|
||||||
if latitude == 0 && longitude == 0 {
|
if latitude == 0 && longitude == 0 {
|
||||||
// In case of using Country DB, city is not available.
|
// In case of using Country DB, city is not available.
|
||||||
loc, ok := coordinates.Country[iso]
|
loc, ok := coordinates.Country[iso]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue