mirror of
https://github.com/retailcrm/api-client-go.git
synced 2025-03-21 23:33:49 +03:00
fix linter
This commit is contained in:
parent
2f33b56cd3
commit
e2113a640e
23
client.go
23
client.go
@ -101,13 +101,14 @@ func (c *Client) executeWithRetry(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
res interface{}
|
res interface{}
|
||||||
statusCode int
|
statusCode int
|
||||||
err error
|
err error
|
||||||
attempt uint = 1
|
lastAttempt bool
|
||||||
maxAttempts = c.limiter.maxAttempts
|
attempt uint = 1
|
||||||
infinite = maxAttempts == 0
|
maxAttempts = c.limiter.maxAttempts
|
||||||
lastAttempt = false
|
totalAttempts = "∞"
|
||||||
|
infinite = maxAttempts == 0
|
||||||
)
|
)
|
||||||
|
|
||||||
var baseDelay time.Duration
|
var baseDelay time.Duration
|
||||||
@ -117,6 +118,10 @@ func (c *Client) executeWithRetry(
|
|||||||
baseDelay = regularDelay
|
baseDelay = regularDelay
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !infinite {
|
||||||
|
totalAttempts = strconv.FormatUint(uint64(maxAttempts), 10)
|
||||||
|
}
|
||||||
|
|
||||||
for infinite || attempt <= maxAttempts {
|
for infinite || attempt <= maxAttempts {
|
||||||
c.applyRateLimit(uri)
|
c.applyRateLimit(uri)
|
||||||
res, statusCode, err = executeFunc()
|
res, statusCode, err = executeFunc()
|
||||||
@ -135,8 +140,8 @@ func (c *Client) executeWithRetry(
|
|||||||
// Calculate exponential backoff delay: baseDelay * 2^(attempt-1).
|
// Calculate exponential backoff delay: baseDelay * 2^(attempt-1).
|
||||||
backoffDelay := baseDelay * (1 << (attempt - 1))
|
backoffDelay := baseDelay * (1 << (attempt - 1))
|
||||||
if c.Debug {
|
if c.Debug {
|
||||||
c.writeLog("API Error: rate limited (503), retrying in %v (attempt %d/%d)",
|
c.writeLog("API Error: rate limited (503), retrying in %v (attempt %d/%s)",
|
||||||
backoffDelay, attempt, maxAttempts)
|
backoffDelay, attempt, totalAttempts)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(backoffDelay)
|
time.Sleep(backoffDelay)
|
||||||
|
2
types.go
2
types.go
@ -15,7 +15,7 @@ const ByID = "id"
|
|||||||
// ByExternalID is "externalId" constant to use as `by` property in methods.
|
// ByExternalID is "externalId" constant to use as `by` property in methods.
|
||||||
const ByExternalID = "externalId"
|
const ByExternalID = "externalId"
|
||||||
|
|
||||||
// RateLimiter configuration constants
|
// RateLimiter configuration constants.
|
||||||
const (
|
const (
|
||||||
regularPathRPS = 10 // API rate limit (requests per second).
|
regularPathRPS = 10 // API rate limit (requests per second).
|
||||||
telephonyPathRPS = 40 // Telephony API endpoints rate limit (requests per second).
|
telephonyPathRPS = 40 // Telephony API endpoints rate limit (requests per second).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user