Last active
March 17, 2017 20:28
-
-
Save beigna/3a18a227cf0c5dfb7d0fa81ed981b636 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 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