method for web download

This commit is contained in:
gutmet 2019-02-11 23:52:19 +01:00
parent bb2d3e26ea
commit c123400a6a

View File

@ -6,6 +6,7 @@ import (
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"os/exec"
"os/user"
@ -310,3 +311,16 @@ func Notify(head string, body string) error {
}
return nil
}
func Download(url string) ([]byte, error) {
resp, err := http.Get(url)
if err != nil {
return nil, errors.New("Download: " + err.Error())
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, errors.New("Download: " + err.Error())
}
return data, err
}