Skip to content

Instantly share code, notes, and snippets.

@beigna
Last active March 17, 2017 20:28
Show Gist options
  • Save beigna/3a18a227cf0c5dfb7d0fa81ed981b636 to your computer and use it in GitHub Desktop.
Save beigna/3a18a227cf0c5dfb7d0fa81ed981b636 to your computer and use it in GitHub Desktop.
func download_file(destination string, url string) error {
fmt.Println("%s -> %s\n", url, destination)
res, err := http.Get(url)
if err != nil {
log.Println(err)
return errors.New("Can't fetch data from URL")
}
defer res.Body.Close()
file, err := os.Create(destination)
if err != nil {
log.Println(err)
return errors.New("Can't open file")
}
io.Copy(file, res.Body)
file.Close()
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment