Improve error reporting inside of geoip lookup functions
This commit is contained in:
parent
5d0e6e6c8c
commit
26feb2bcce
|
@ -163,7 +163,7 @@ func akamaiLookup() (string, error) {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
req, err := http.NewRequest("GET", "https://a248.e.akamai.net/", nil)
|
req, err := http.NewRequest("GET", "https://a248.e.akamai.net/", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", errors.Wrap(err, "failed to create NewRequest")
|
||||||
}
|
}
|
||||||
req.Host = "whatismyip.akamai.com"
|
req.Host = "whatismyip.akamai.com"
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
@ -187,18 +187,23 @@ var lookupServices = []lookupFunc{
|
||||||
|
|
||||||
// IPLookup gets the users IP address from a IP lookup service
|
// IPLookup gets the users IP address from a IP lookup service
|
||||||
func IPLookup() (string, error) {
|
func IPLookup() (string, error) {
|
||||||
rand.Seed(time.Now().Unix())
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
ipStr string
|
||||||
|
)
|
||||||
|
|
||||||
retries := 3
|
retries := 3
|
||||||
for retries > 0 {
|
for retries > 0 {
|
||||||
lookup := lookupServices[rand.Intn(len(lookupServices))]
|
lookup := lookupServices[rand.Intn(len(lookupServices))]
|
||||||
ipStr, err := lookup()
|
ipStr, err = lookup()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return ipStr, nil
|
return ipStr, nil
|
||||||
}
|
}
|
||||||
retries--
|
retries--
|
||||||
}
|
}
|
||||||
return "", errors.New("exceeded maximum retries")
|
return "", errors.Wrap(err, "exceeded maximum retries")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GeoIPLookup does a geoip lookup and returns location information
|
// GeoIPLookup does a geoip lookup and returns location information
|
||||||
|
|
Loading…
Reference in New Issue
Block a user