From ba5649d2597c6d89f4c609d1246837f0172a722b Mon Sep 17 00:00:00 2001 From: Wim Date: Sat, 4 Nov 2017 14:55:25 +0100 Subject: Add helper --- bridge/helper/helper.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 bridge/helper/helper.go (limited to 'bridge/helper/helper.go') diff --git a/bridge/helper/helper.go b/bridge/helper/helper.go new file mode 100644 index 00000000..ecfc4df2 --- /dev/null +++ b/bridge/helper/helper.go @@ -0,0 +1,28 @@ +package helper + +import ( + "bytes" + "io" + "net/http" + "time" +) + +func DownloadFile(url string) (*[]byte, error) { + var buf bytes.Buffer + client := &http.Client{ + Timeout: time.Second * 5, + } + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return nil, err + } + resp, err := client.Do(req) + if err != nil { + resp.Body.Close() + return nil, err + } + io.Copy(&buf, resp.Body) + data := buf.Bytes() + resp.Body.Close() + return &data, nil +} -- cgit v1.2.3