method for web download
This commit is contained in:
parent
bb2d3e26ea
commit
c123400a6a
14
goutil.go
14
goutil.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user