acme: use built-in max/min to simplify the code

Change-Id: I6ba8d07b9e53b01f25f4c1c8eac629aaa47de3a1
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/664836
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
cuishuang
2025-04-11 09:06:14 -07:00
committed by Roland Shoemaker
parent c96bba2ced
commit 4bc0711281
+2 -5
View File
@@ -66,7 +66,7 @@ func (c *Client) retryTimer() *retryTimer {
// The n argument is always bounded between 1 and 30.
// The returned value is always greater than 0.
func defaultBackoff(n int, r *http.Request, res *http.Response) time.Duration {
const max = 10 * time.Second
const maxVal = 10 * time.Second
var jitter time.Duration
if x, err := rand.Int(rand.Reader, big.NewInt(1000)); err == nil {
// Set the minimum to 1ms to avoid a case where
@@ -86,10 +86,7 @@ func defaultBackoff(n int, r *http.Request, res *http.Response) time.Duration {
n = 30
}
d := time.Duration(1<<uint(n-1))*time.Second + jitter
if d > max {
return max
}
return d
return min(d, maxVal)
}
// retryAfter parses a Retry-After HTTP header value,