diff --git a/catalogue/catalogue.go b/catalogue/catalogue.go index 144ab06c..6b6fee99 100644 --- a/catalogue/catalogue.go +++ b/catalogue/catalogue.go @@ -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 diff --git a/client/registry.go b/client/registry.go index 0f9f8949..91618e1c 100644 --- a/client/registry.go +++ b/client/registry.go @@ -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 diff --git a/web/web.go b/web/web.go index c1f8297b..1baca7da 100644 --- a/web/web.go +++ b/web/web.go @@ -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