fix linter

This commit is contained in:
Pavel 2025-03-18 17:00:42 +03:00
parent 2f33b56cd3
commit e2113a640e
2 changed files with 15 additions and 10 deletions

View File

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

View File

@ -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).