// rateLimitBackoff provides a callback for Client.Backoff which will use the
// X-RateLimit_Reset header to determine the time to wait. We add some jitter
// to prevent a thundering herd.
//
// min and max are mainly used for bounding the jitter that will be added to
// the reset time retrieved from the headers. But if the final wait time is
// less then min, min will be used instead.
rateLimitBackoff provides a callback for Client.Backoff which will use the
X-RateLimit_Reset header to determine the time to wait. We add some jitter
to prevent a thundering herd.

min and max are mainly used for bounding the jitter that will be added to
the reset time retrieved from the headers. But if the final wait time is
less then min, min will be used instead.
// rateLimitBackoff provides a callback for Client . Backoff which will use the // X - RateLimit_Reset header to determine the time to wait . We add some jitter // to prevent a thundering herd . // // min and max are mainly used for bounding the jitter that will be added to // the reset time retrieved from the headers . But if the final wait time is // less then min min will be used instead .
func rateLimitBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
	rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
	jitter := time.Duration(rnd.Float64() * float64(max-min))
	if resp != nil {
		if v := resp.Header.Get(headerRateReset); v != "" {
			if reset, _ := strconv.ParseFloat(v, 64); reset > 0 {
				if wait := time.Duration(reset * 1e9); wait > min {
					min = wait
				}
			}
		}
	}
	return min + jitter
}
func rateLimitBackoff ( min , max time . Duration , attemptNum int , resp * http . Response ) time . Duration { rnd := rand . New ( rand . NewSource ( time . Now ( ) . UnixNano ( ) ) ) jitter := time . Duration ( rnd . Float64 ( ) * float64 ( max - min ) ) if resp != nil { if v := resp . Header . Get ( headerRateReset ) ; v != " " { if reset , _ := strconv . ParseFloat ( v , 64 ) ; reset > 0 { if wait := time . Duration ( reset * 1e9 ) ; wait > min { min = wait } } } } return min + jitter }
rateLimitBackoff provides a callback for Client.Backoff which will use the
X-RateLimit_Reset header to determine the time to wait.
rateLimitBackoff provides a callback for Client . Backoff which will use the X - RateLimit_Reset header to determine the time to wait .
// rnd is used to generate pseudo-random numbers. // First create some jitter bounded by the min and max durations. // Only update min if the given time to wait is longer.