Initial commit after restructure

This commit is contained in:
Daniel
2018-08-13 14:14:27 +02:00
commit bdeddc41f9
177 changed files with 26108 additions and 0 deletions

45
network/geoip/lookup.go Normal file
View File

@@ -0,0 +1,45 @@
package geoip
import (
"net"
)
// GetLocation returns Location data of an IP address
func GetLocation(ip net.IP) (record *Location, err error) {
dbLock.Lock()
defer dbLock.Unlock()
err = prepDatabaseForUse()
if err != nil {
return nil, err
}
record = &Location{}
// fetch
err = dbCity.Lookup(ip, record)
if err == nil {
err = dbASN.Lookup(ip, record)
}
// retry
if err != nil {
// reprep
handleError(err)
err = prepDatabaseForUse()
if err != nil {
return nil, err
}
// refetch
err = dbCity.Lookup(ip, record)
if err == nil {
err = dbASN.Lookup(ip, record)
}
}
if err != nil {
return nil, err
}
return record, nil
}