下载文件的最简单方法?

I can do something like below, which gives me a response class, but I'm not exactly sure how to write the io.reader to a file. What is the most straightforward way?

http.Get("https://www.domain.com/some.jpg")

If the file is small enough the easiest solution is to use ioutil.WriteFile combined with ioutil.ReadAll :

resp, err := http.Get("your url")
bytes, err := ioutil.ReadAll(resp.Body)
err = ioutil.WriteFile(filename, bytes, 0666)

If your file isn't so small, you'd better avoid creating and filling the bytes array. Then you should use io.Copy which simply copies the bytes from the reader to the writer :

resp, err := http.Get("your url")
f, err := os.Create(filename)
defer f.Close()
_, err := io.Copy(f, resp.Body)

You must add the relevant error handling in both cases.