From c123400a6a0352d8e5c074130f9fdbd74b98409b Mon Sep 17 00:00:00 2001 From: gutmet Date: Mon, 11 Feb 2019 23:52:19 +0100 Subject: [PATCH] method for web download --- goutil.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/goutil.go b/goutil.go index 99a5a6d..f8aac3b 100644 --- a/goutil.go +++ b/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 +}