func DownloadFile filepath url string error out err os Create filepath

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
func DownloadFile(filepath, url string) error {
out, err := os.Create(filepath)
if (err != nil) {
return err
}
defer out.Close()
resp, err := http.Get(url)
if (err != nil) {
return err
}
defer resp.Body.Close()
_, err = io.Copy(out, resp.Body)
if (err != nil) {
return err
}
return nil
}