refactor: use web module timeout everywhere

This commit is contained in:
decentral1se 2021-09-04 23:18:34 +02:00
parent e68c7fc71c
commit a3e02540f6
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
3 changed files with 8 additions and 5 deletions

View File

@ -142,7 +142,7 @@ func (a ByAppName) Less(i, j int) bool {
var appsCatalogueURL = "https://apps.coopcloud.tech"
func appsCatalogueFSIsLatest() (bool, error) {
httpClient := &http.Client{Timeout: 5 * time.Second}
httpClient := &http.Client{Timeout: web.Timeout}
res, err := httpClient.Head(appsCatalogueURL)
if err != nil {
return false, err

View File

@ -6,7 +6,6 @@ import (
"io/ioutil"
"net/http"
"strings"
"time"
"coopcloud.tech/abra/web"
"github.com/docker/distribution/reference"
@ -41,7 +40,7 @@ func getRegv2Token(image reference.Named) (string, error) {
return "", err
}
client := &http.Client{Timeout: 10 * time.Second}
client := &http.Client{Timeout: web.Timeout}
res, err := client.Do(req)
if err != nil {
return "", err
@ -97,7 +96,7 @@ func GetTagDigest(image reference.Named) (string, error) {
"Authorization": []string{fmt.Sprintf("Bearer %s", token)},
}
client := &http.Client{Timeout: 10 * time.Second}
client := &http.Client{Timeout: web.Timeout}
res, err := client.Do(req)
if err != nil {
return "", err

View File

@ -6,9 +6,13 @@ import (
"time"
)
// Timeout is the time it takes before a web request bails out waiting for a
// request.
const Timeout = 10 * time.Second
// ReadJSON reads JSON and parses it into your chosen interface pointer
func ReadJSON(url string, target interface{}) error {
httpClient := &http.Client{Timeout: 5 * time.Second}
httpClient := &http.Client{Timeout: Timeout}
res, err := httpClient.Get(url)
if err != nil {
return err