Skip to content

Instantly share code, notes, and snippets.

@dhanush
Last active January 23, 2022 06:44
Show Gist options
  • Save dhanush/860d1695cda1813b27f9f1e26896422b to your computer and use it in GitHub Desktop.
Save dhanush/860d1695cda1813b27f9f1e26896422b to your computer and use it in GitHub Desktop.
func downloadFile(URL string) ([]byte, error) {
response, err := http.Get(URL)
if err != nil {
return nil, err
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
return nil, errors.New(response.Status)
}
var data bytes.Buffer
_, err = io.Copy(&data, response.Body)
if err != nil {
return nil, err
}
return data.Bytes(), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment