Documentation
¶
Overview ¶
Package ratelimit enforces Seznam's published limits across processes.
Agents usually call a CLI in a loop, starting a new process per URL, so an in-memory limiter would protect nothing. Call timestamps live in a small state file keyed by a fingerprint of the API key (never the key itself).
State is best effort: if it cannot be read or written, szwm falls back to an in-process limiter rather than failing the API call.
Index ¶
Constants ¶
const ( PerSecond = 5 PerMinute = 100 ReindexPerDay = 500 QuotaTimezone = "Europe/Prague" )
Published limits, per user and per site.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Ledger ¶
type Ledger struct {
// contains filtered or unexported fields
}
Ledger counts successful reindex requests per day.
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter is a sliding-window limiter shared between processes.
func NewLimiter ¶
NewLimiter returns a limiter for one key fingerprint.
type Quota ¶
type Quota struct {
Day string `json:"day"`
Timezone string `json:"timezone"`
Limit int `json:"limit"`
Used int `json:"used_estimate"`
Remaining int `json:"remaining_estimate"`
Estimated bool `json:"estimated"`
}
Quota is a snapshot of the local reindex ledger.
The API exposes no counter, so this is an estimate of calls made from this machine. Seznam does not document when "a day" starts; szwm assumes midnight in Europe/Prague.