create a new instance of http.Client with timeout

This commit is contained in:
Dawid Wysokiński 2020-06-21 17:25:15 +02:00 committed by Kichiyaki
parent a90daa1886
commit 542b6301b0
2 changed files with 9 additions and 3 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
.env.development
.env.production
.env
.netrc
.netrc
todo.sql

View File

@ -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
}