package retryafter
import "go.mau.fi/util/retryafter"
Package retryafter contains a utility function for parsing the Retry-After HTTP header.
Index ¶
- func Parse(retryAfter string, fallback time.Duration) time.Duration
- func Should(statusCode int, retryOnRateLimit bool) bool
Functions ¶
func Parse ¶
Parse parses the backoff time specified in the Retry-After header if present. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After.
The second parameter is the fallback duration to use if the header is not present or invalid.
Example:
time.Sleep(retryafter.Parse(resp.Header.Get("Retry-After"), 5*time.Second))
func Should ¶
Should returns true if the given status code indicates that the request should be retried.
if retryafter.Should(resp.StatusCode, true) { time.Sleep(retryafter.Parse(resp.Header.Get("Retry-After"), 5*time.Second)) }
Source Files ¶
retryafter.go
- Version
- v0.8.6 (latest)
- Published
- Mar 16, 2025
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 1 week ago –
Tools for package owners.