Skip to content

Commit

Permalink
improve readability - pseudo pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
rayshoo committed Nov 14, 2024
1 parent 7fb8be1 commit 67ff232
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions provider/godaddy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,16 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
resp, err := c.Client.Do(req)
// In case of several clients behind NAT we still can hit rate limit
for i := 1; i < 3 && err == nil && resp.StatusCode == 429; i++ {
var retryAfter int64
var jitter int64
if headerValue := resp.Header.Get("Retry-After"); headerValue == "" {
retryAfter = 30
} else {
retryAfter, _ = strconv.ParseInt(headerValue, 10, 0)
var retryAfterSec int64 = 30

receivedValue := resp.Header.Get("Retry-After")
if receivedValue != "" {
retryAfter, _ := strconv.ParseInt(receivedValue, 10, 0)
if retryAfter > 0 {
jitter = rand.Int63n(retryAfter)
jitter := rand.Int63n(retryAfter)
retryAfterSec = retryAfter + jitter/2
}
}
retryAfterSec := retryAfter + jitter/2

sleepTime := time.Duration(retryAfterSec) * time.Second
time.Sleep(sleepTime)
Expand Down

0 comments on commit 67ff232

Please sign in to comment.