Documentation
¶
Index ¶
- Constants
- func Chain(mw ...types.Middleware) types.Middleware
- func New(opts ...Option) (*http.Client, error)
- func NewTokenBucketLimiter(ratePerSec float64, burst int, jitterFraction float64) (*tokenBucketLimiter, error)
- type Limiter
- type Metrics
- type Middleware
- type Option
- func WithBaseTransport(rt http.RoundTripper) Option
- func WithClientName(name string) Option
- func WithDeadlineThreshold(t time.Duration) Option
- func WithHedge(opts ...hedge.Option) Option
- func WithJitter(fraction float64) Option
- func WithMetrics(m *Metrics) Option
- func WithRateLimit(rate float64, burst int) Option
- func WithServerHeaderJitter(fraction float64) Option
- type RoundTripperFunc
Constants ¶
const ( LabelClient = types.LabelClient LabelHost = types.LabelHost LabelMethod = types.LabelMethod LabelSource = types.LabelSource )
Label constants for backward compatibility.
Variables ¶
This section is empty.
Functions ¶
func Chain ¶
func Chain(mw ...types.Middleware) types.Middleware
Chain builds a middleware pipeline.
Types ¶
type Metrics ¶
Metrics is an alias for types.Metrics for backward compatibility.
func NewMetrics ¶
NewMetrics creates a new Metrics instance.
type Middleware ¶
type Middleware = types.Middleware
Middleware is an alias for types.Middleware for backward compatibility.
type Option ¶
type Option func(*config) error
Option configures an HTTP client during construction.
func WithBaseTransport ¶
func WithBaseTransport(rt http.RoundTripper) Option
WithBaseTransport sets the base HTTP transport to wrap with middleware. If nil, http.DefaultTransport is used.
func WithClientName ¶
WithClientName sets the client name used for metrics and tracing.
func WithDeadlineThreshold ¶
WithDeadlineThreshold sets the minimum time before a context deadline at which requests will be rejected early. If a request's deadline is closer than this threshold, it will be canceled immediately.
func WithHedge ¶
WithHedge enables adaptive hedged requests on the stack below OpenTelemetry (otelhttp remains the outer RoundTripper so each logical Do keeps one trace span). See https://github.com/bhope/hedge
func WithJitter ¶
WithJitter sets the jitter fraction for the token bucket limiter. Fraction should be between 0 and 1. Negative values are normalized to 0, values greater than 1 are normalized to 1.
func WithMetrics ¶
WithMetrics sets the Prometheus metrics collector.
func WithRateLimit ¶
WithRateLimit configures the local token bucket rate limiter. Rate is in requests per second, burst is the maximum number of tokens. Both must be positive for the limiter to be created.
func WithServerHeaderJitter ¶
WithServerHeaderJitter sets the jitter fraction for server rate limit waits. Fraction should be between 0 and 1. Negative values are normalized to 0, values greater than 1 are normalized to 1.
type RoundTripperFunc ¶
type RoundTripperFunc = types.RoundTripperFunc
RoundTripperFunc is an alias for types.RoundTripperFunc for backward compatibility.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
middleware
|
|
|
serverlimit
Package serverlimit provides HTTP client middleware for respecting server-specified rate limits via Retry-After and RateLimit-Reset headers.
|
Package serverlimit provides HTTP client middleware for respecting server-specified rate limits via Retry-After and RateLimit-Reset headers. |