5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-25 16:51:35 +00:00
matterbridge/bridge/helper/helper.go

29 lines
448 B
Go
Raw Normal View History

2017-11-04 13:55:25 +00:00
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
}