canape/web/download.go

31 lines
447 B
Go

package web
import (
"io"
"net/http"
"os"
)
// Download used for downloading file
var Download = func(srcURL, dest string) error {
resp, err := http.Get(srcURL)
if err != nil {
return err
}
defer resp.Body.Close()
// Create the file
file, err := os.Create(dest)
if err != nil {
return err
}
defer file.Close()
// Write from the net to the file
_, err = io.Copy(file, resp.Body)
if err != nil {
return err
}
return nil
}