From e2113a640e82c44d999175f1727fcf0f75952b8e Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Tue, 18 Mar 2025 17:00:42 +0300 Subject: [PATCH] fix linter --- client.go | 23 ++++++++++++++--------- types.go | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index f94e587..1a62f0c 100644 --- a/client.go +++ b/client.go @@ -101,13 +101,14 @@ func (c *Client) executeWithRetry( } var ( - res interface{} - statusCode int - err error - attempt uint = 1 - maxAttempts = c.limiter.maxAttempts - infinite = maxAttempts == 0 - lastAttempt = false + res interface{} + statusCode int + err error + lastAttempt bool + attempt uint = 1 + maxAttempts = c.limiter.maxAttempts + totalAttempts = "∞" + infinite = maxAttempts == 0 ) var baseDelay time.Duration @@ -117,6 +118,10 @@ func (c *Client) executeWithRetry( baseDelay = regularDelay } + if !infinite { + totalAttempts = strconv.FormatUint(uint64(maxAttempts), 10) + } + for infinite || attempt <= maxAttempts { c.applyRateLimit(uri) res, statusCode, err = executeFunc() @@ -135,8 +140,8 @@ func (c *Client) executeWithRetry( // Calculate exponential backoff delay: baseDelay * 2^(attempt-1). backoffDelay := baseDelay * (1 << (attempt - 1)) if c.Debug { - c.writeLog("API Error: rate limited (503), retrying in %v (attempt %d/%d)", - backoffDelay, attempt, maxAttempts) + c.writeLog("API Error: rate limited (503), retrying in %v (attempt %d/%s)", + backoffDelay, attempt, totalAttempts) } time.Sleep(backoffDelay) diff --git a/types.go b/types.go index 94e4d3c..50cbc13 100644 --- a/types.go +++ b/types.go @@ -15,7 +15,7 @@ const ByID = "id" // ByExternalID is "externalId" constant to use as `by` property in methods. const ByExternalID = "externalId" -// RateLimiter configuration constants +// RateLimiter configuration constants. const ( regularPathRPS = 10 // API rate limit (requests per second). telephonyPathRPS = 40 // Telephony API endpoints rate limit (requests per second).