mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-09 23:40:27 +00:00
Add helper
This commit is contained in:
parent
1b30575510
commit
ba5649d259
28
bridge/helper/helper.go
Normal file
28
bridge/helper/helper.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user