mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
24 lines
314 B
Go
24 lines
314 B
Go
package downloader
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func Download(url, filename string) error {
|
|
resp, err := http.Get(url)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
f, err := os.Create(filename)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
_, err = io.Copy(f, resp.Body)
|
|
return err
|
|
}
|