Documentation
¶
Overview ¶
Package ratelimit keeps a GitHub API client from spending requests to rediscover that it has none left.
GitHub answers an exhausted allowance with a 403 whose body reads like a permissions failure, so a client that does not inspect the headers reports the wrong cause and a retry loop spends a request per attempt learning the same thing. Transport turns that response into a typed error naming when the allowance returns, and refuses further requests to that pool until it does.
The pools are separate allowances rather than slices of one, so being out of core does not stop a GraphQL query. Pair this with a proactive read of what is left (forge/github.Budgets) to decide whether a burst is affordable before starting it.
Index ¶
Constants ¶
const ( HeaderRemaining = "X-RateLimit-Remaining" HeaderReset = "X-RateLimit-Reset" HeaderLimit = "X-RateLimit-Limit" HeaderResource = "X-RateLimit-Resource" HeaderRetryAfter = "Retry-After" )
Header names GitHub sets on every API response.
const ( PoolCore = "core" PoolGraphQL = "graphql" PoolSearch = "search" )
Pool names one of GitHub's separate hourly allowances.
Variables ¶
This section is empty.
Functions ¶
func Transport ¶
func Transport(base http.RoundTripper) http.RoundTripper
Transport wraps base so an exhausted allowance surfaces as *Error and later requests to that pool fail immediately until it resets. Requests to a pool with allowance left are unaffected.
Types ¶
type Error ¶
Error reports an exhausted allowance and when it returns. Retrying before RetryAt fails without spending a request, so a caller should show the time rather than offering an immediate retry.