Skip to content

Instantly share code, notes, and snippets.

@marawannwh
Created May 28, 2021 14:35
Show Gist options
  • Save marawannwh/27d7eec4bf698df22de888acb7a72531 to your computer and use it in GitHub Desktop.
Save marawannwh/27d7eec4bf698df22de888acb7a72531 to your computer and use it in GitHub Desktop.
func fetchInstances() (map[string]interface{}, error) {
jsonStr := []byte(`{
"older_than": ` + olderThan + `,
"limit": ` + instancesToFetch + `,
}`)
req, err := http.NewRequest("GET", fetchInstancesURL, bytes.NewBuffer(jsonStr))
req.Header.Set("Authorization", apiSecret)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{
Timeout: 30 * time.Second,
}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
result := map[string]interface{}{}
err = json.Unmarshal(body, &result)
if err != nil {
return nil, err
}
return result, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment