go-zero/tools/goctl/pkg/downloader/downloader.go
2022-03-23 19:09:45 +08:00

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
}