Rename the atomic methods.

This commit is contained in:
zicla
2019-04-25 02:13:34 +08:00
parent 1416344b06
commit b2a3e4e225
5 changed files with 67 additions and 130 deletions

View File

@ -366,33 +366,11 @@ func DownloadFile(
// 从指定的url下载一个文件。参考https://golangcode.com/download-a-file-from-a-url/
func HttpDownloadFile(filepath string, url string) (int64, error) {
// Create the file
out, err := os.Create(filepath)
if err != nil {
return 0, err
}
defer func() {
e := out.Close()
PanicError(e)
}()
func HttpDownloadFile(url string) io.Reader {
// Get the data
resp, err := http.Get(url)
if err != nil {
return 0, err
}
defer func() {
e := resp.Body.Close()
PanicError(e)
}()
PanicError(err)
// Write the body to file
size, err := io.Copy(out, resp.Body)
if err != nil {
return 0, err
}
return size, nil
return resp.Body
}