create a new instance of http.Client with timeout
This commit is contained in:
parent
a90daa1886
commit
542b6301b0
|
@ -1,4 +1,5 @@
|
|||
.env.development
|
||||
.env.production
|
||||
.env
|
||||
.netrc
|
||||
.netrc
|
||||
todo.sql
|
|
@ -7,10 +7,15 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/tribalwarshelp/shared/models"
|
||||
)
|
||||
|
||||
var client = &http.Client{
|
||||
Timeout: 20 * time.Second,
|
||||
}
|
||||
|
||||
func uncompressAndGetCsvLines(r io.Reader) ([][]string, error) {
|
||||
uncompressedStream, err := gzip.NewReader(r)
|
||||
if err != nil {
|
||||
|
@ -21,7 +26,7 @@ func uncompressAndGetCsvLines(r io.Reader) ([][]string, error) {
|
|||
}
|
||||
|
||||
func getCSVData(url string, compressed bool) ([][]string, error) {
|
||||
resp, err := http.Get(url)
|
||||
resp, err := client.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -33,7 +38,7 @@ func getCSVData(url string, compressed bool) ([][]string, error) {
|
|||
}
|
||||
|
||||
func getXML(url string, decode interface{}) error {
|
||||
resp, err := http.Get(url)
|
||||
resp, err := client.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Reference in New Issue