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:
kayos@tcp.direct 2022-12-06 20:26:46 -08:00
parent e878e4820a
commit 4c4cd6eb4d
No known key found for this signature in database
GPG key ID: 4B841471B4BEE979

View file

@ -162,29 +162,18 @@ func GetPublicIP(api string) (string, error) {
iplist = append([]string{api}, iplist...)
}
var bodies []*http.Response
defer func() {
for _, res := range bodies {
if res != nil {
_ = res.Body.Close()
}
}
}()
endpoint := ""
var err error
for _, ipserver := range iplist {
client := &http.Client{
Timeout: time.Second * 10,
}
var resp *http.Response
resp, err = client.Get(ipserver)
if err != nil {
continue
}
bodies = append(bodies, resp)
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
var bodyBytes []byte
bodyBytes, err = io.ReadAll(resp.Body)