Fill missing location info based on existing info

This commit is contained in:
Daniel
2021-09-29 22:10:45 +02:00
parent b370eec04e
commit d98df900bd
5 changed files with 279 additions and 17 deletions

View File

@@ -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
}