From 551cb3c61ce864fefa4901f805f93f12eeda7921 Mon Sep 17 00:00:00 2001 From: Jiri Vrba Date: Fri, 16 Feb 2024 20:31:24 +0100 Subject: [PATCH] Fix: use Golang style --- src/pkg/reg/adapter/dockerhub/adapter.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/pkg/reg/adapter/dockerhub/adapter.go b/src/pkg/reg/adapter/dockerhub/adapter.go index 83f56544e7f1..0a4b060a6d04 100644 --- a/src/pkg/reg/adapter/dockerhub/adapter.go +++ b/src/pkg/reg/adapter/dockerhub/adapter.go @@ -134,8 +134,8 @@ func getAdapterInfo() *model.AdapterPattern { // // so it is better to not hit the wall. func (a *adapter) limitAwareDo(method string, path string, body io.Reader) (*http.Response, error) { - var attempts_left int = 3 - for attempts_left > 0 { + var attemptsLeft = 3 + for attemptsLeft > 0 { resp, err := a.client.Do(method, path, body) if err != nil { return resp, err @@ -149,24 +149,23 @@ func (a *adapter) limitAwareDo(method string, path string, body io.Reader) (*htt time.Sleep(time.Duration(seconds * 1000 * 1000 * 1000)) log.Info("Sleep finished, resuming operation") } else { - remaining_req, err := strconv.ParseInt(resp.Header.Get("x-ratelimit-remaining"), 10, 64) + reqsLeft, err := strconv.ParseInt(resp.Header.Get("x-ratelimit-remaining"), 10, 64) if err != nil { return resp, err } - if remaining_req < 8 { - reset_at, err := strconv.ParseInt(resp.Header.Get("x-ratelimit-reset"), 10, 64) + if reqsLeft < 8 { + resetTSC, err := strconv.ParseInt(resp.Header.Get("x-ratelimit-reset"), 10, 64) if err != nil { return resp, err } - seconds := reset_at - time.Now().Unix() + seconds := resetTSC - time.Now().Unix() log.Infof("Ratelimit exhaustion eminent, sleeping for %d seconds", seconds) time.Sleep(time.Duration(seconds * 1000 * 1000 * 1000)) log.Info("Sleep finished, resuming operation") - } return resp, err } - attempts_left-- + attemptsLeft-- } return nil, errors.New("unable to get past dockerhub rate-limit") }