From c9ad00fc130b1ad85e0cf542c13e4f15d1273877 Mon Sep 17 00:00:00 2001 From: IP2Location Date: Thu, 18 Jan 2024 14:24:08 +0800 Subject: [PATCH] Added IP2Location.io API Signed-off-by: IP2Location --- edge/services/gps/src/hgps/hgps.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/edge/services/gps/src/hgps/hgps.go b/edge/services/gps/src/hgps/hgps.go index 76efc9e27..87d4255a5 100644 --- a/edge/services/gps/src/hgps/hgps.go +++ b/edge/services/gps/src/hgps/hgps.go @@ -400,9 +400,13 @@ func get_public_address() (err error, ip_address string) { provider_url := "http://ifconfig.co" resp, rest_err := http.Get(provider_url) if rest_err != nil { - ip_address = "" - err = errors.New(fmt.Sprintf("ERROR: REST call to %s failed: %v", provider_url, rest_err)) - return + provider_url = "http://ip2location.io/ip" // secondary + resp, rest_err = http.Get(provider_url) + if rest_err != nil { + ip_address = "" + err = errors.New(fmt.Sprintf("ERROR: REST call to %s failed: %v", provider_url, rest_err)) + return + } } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) @@ -425,8 +429,12 @@ func get_location_from_ip_address(ip_address string) (lat float64, lon float64, url := "http://api.ipstack.com/" + ip_address + "?access_key=" + apikey + "&format=1" resp, rest_err := http.Get(url) if rest_err != nil { - err = errors.New(fmt.Sprintf("ERROR: Request to %s failed: %v", url, rest_err)) - return + url := "http://api.ip2location.io?ip=" + ip_address + resp, rest_err = http.Get(url) + if rest_err != nil { + err = errors.New(fmt.Sprintf("ERROR: Request to %s failed: %v", url, rest_err)) + return + } } defer resp.Body.Close() httpCode := resp.StatusCode