Last active
January 23, 2022 06:44
-
-
Save dhanush/860d1695cda1813b27f9f1e26896422b 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 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