mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 16:57:51 +08:00
Revert: changing mechanics of loop (for ease of pr review)
cherry-pick the ineffective `err` assignment to make our following error check not useless
This commit is contained in:
@@ -162,29 +162,18 @@ func GetPublicIP(api string) (string, error) {
|
|||||||
iplist = append([]string{api}, iplist...)
|
iplist = append([]string{api}, iplist...)
|
||||||
}
|
}
|
||||||
|
|
||||||
var bodies []*http.Response
|
|
||||||
defer func() {
|
|
||||||
for _, res := range bodies {
|
|
||||||
if res != nil {
|
|
||||||
_ = res.Body.Close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
endpoint := ""
|
endpoint := ""
|
||||||
var err error
|
var err error
|
||||||
for _, ipserver := range iplist {
|
for _, ipserver := range iplist {
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Timeout: time.Second * 10,
|
Timeout: time.Second * 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
resp, err = client.Get(ipserver)
|
resp, err = client.Get(ipserver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
bodies = append(bodies, resp)
|
|
||||||
if resp.StatusCode == http.StatusOK {
|
if resp.StatusCode == http.StatusOK {
|
||||||
var bodyBytes []byte
|
var bodyBytes []byte
|
||||||
bodyBytes, err = io.ReadAll(resp.Body)
|
bodyBytes, err = io.ReadAll(resp.Body)
|
||||||
|
Reference in New Issue
Block a user