Skip to content

Instantly share code, notes, and snippets.

@akovardin
Created December 11, 2018 21:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akovardin/5eecccd438deed69e5acca24cb670361 to your computer and use it in GitHub Desktop.
Save akovardin/5eecccd438deed69e5acca24cb670361 to your computer and use it in GitHub Desktop.
Image Download
func DownloadFile(filepath string, url string) error {
// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
// Create the file
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()
// Write the body to file
_, err = io.Copy(out, resp.Body)
if err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment