Created
May 28, 2021 14:35
-
-
Save marawannwh/27d7eec4bf698df22de888acb7a72531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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