Skip to content
This repository has been archived by the owner on Sep 20, 2022. It is now read-only.

Commit

Permalink
Updated getJson to close the response body correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Rucknar committed Dec 23, 2016
1 parent cb3f1d5 commit 1b22636
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func GetJson(url string, accessKey string, secretKey string, target interface{})
log.Info("Scraping: ", url)

client := &http.Client{}

req, err := http.NewRequest("GET", url, nil)

req.SetBasicAuth(accessKey, secretKey)
Expand All @@ -32,11 +33,17 @@ func GetJson(url string, accessKey string, secretKey string, target interface{})
panic(err)
}

respFormatted := json.NewDecoder(resp.Body).Decode(target)

// Timings recorded as part of internal metrics
elapsed := float64((time.Since(start)) / time.Microsecond)
measure.FunctionDurations.WithLabelValues("hosts", "getJSON").Observe(elapsed)

return json.NewDecoder(resp.Body).Decode(target)
// Close the response body, the underlying Transport should then close the connection.
resp.Body.Close()

// return formatted JSON
return respFormatted
}

// StacksURLCheck - Checks the API version for Rancher to determine the correct URL
Expand Down

0 comments on commit 1b22636

Please sign in to comment.