Documentation
¶
Overview ¶
Package ratelimit reads the quota a server reports in its response headers: the RateLimit and RateLimit-Policy fields of the IETF draft (draft-ietf-httpapi-ratelimit-headers, still a draft: its field names may change), and the RateLimit-Limit/-Remaining/-Reset and X-RateLimit-* headers servers sent before it. A client can show what is left and wait for the quota to come back instead of failing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct {
Policy string // the draft's policy name, "" for the older headers
Limit int // requests allowed in the window; -1 when unknown
Remaining int // requests left; -1 when unknown
Reset time.Duration // until the quota is back
Window time.Duration // the policy's window, when the server gave it
}
Info is the quota a response reported. A figure the server did not give is -1 (Limit, Remaining) or zero.
func Read ¶
Read reads the quota from the headers of a response received at now; found is false when it reports none. With several policies the one with the least left is returned.