Fill missing location info based on existing info
This commit is contained in:
@@ -12,15 +12,17 @@ func getReader(ip net.IP) *maxminddb.Reader {
|
||||
return worker.GetReader(isV6, true)
|
||||
}
|
||||
|
||||
// GetLocation returns Location data of an IP address
|
||||
// GetLocation returns Location data of an IP address.
|
||||
func GetLocation(ip net.IP) (*Location, error) {
|
||||
db := getReader(ip)
|
||||
if db == nil {
|
||||
return nil, fmt.Errorf("geoip database not available")
|
||||
}
|
||||
var record Location
|
||||
if err := db.Lookup(ip, &record); err != nil {
|
||||
record := &Location{}
|
||||
if err := db.Lookup(ip, record); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &record, nil
|
||||
|
||||
record.FillMissingInfo()
|
||||
return record, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user