Documentation
¶
Overview ¶
Package limit paces how often the server is allowed to drive a browser at X.
Fetching too eagerly is what gets a session flagged, so every uncached path goes through a budget. Reads and writes each get their own.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Budget ¶
type Budget struct {
// contains filtered or unexported fields
}
Budget enforces a floor between calls and a ceiling within a rolling window.
func (*Budget) Remaining ¶
Remaining reports how many calls are still available in the current window.
func (*Budget) Wait ¶
Wait blocks until the caller may proceed, then records the call.
It returns *ExhaustedError when the window is full — that is a real answer for the caller to surface, not something to wait out, since the wait could be most of the window.
The lock is never held while sleeping: a slow caller would otherwise stall every other request behind it for the whole interval.
type ExhaustedError ¶
ExhaustedError reports that the rolling budget is spent.
func (*ExhaustedError) Error ¶
func (e *ExhaustedError) Error() string
type Params ¶ added in v0.0.4
type Params struct {
MinInterval time.Duration
Window time.Duration
Max int
// Jitter spreads the gap between calls over MinInterval..MinInterval+Jitter.
//
// A fixed interval is itself a signature: nothing human acts at exactly the
// same spacing every time. It matters for actions X can see as engagement,
// and not at all for reads.
Jitter time.Duration
}
Params configures a Budget.