go-zero/tools/goctl/pkg/downloader/downloader.go

24 lines
314 B
Go
Raw Normal View History

2022-02-21 10:19:33 +08:00
package downloader
import (
"io"
"net/http"
"os"
)
2022-03-23 19:09:45 +08:00
func Download(url, filename string) error {
2022-02-21 10:19:33 +08:00
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
}