Created
December 11, 2018 21:37
-
-
Save akovardin/5eecccd438deed69e5acca24cb670361 to your computer and use it in GitHub Desktop.
Image Download
This file contains hidden or 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(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