Documentation ¶
Overview ¶
Package ratelimit implements rate limiting for the public Riot API.
This package defines client-side rate limiting. For centralized rate limiting, see the service sub-package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cancel ¶
type Cancel func() error
Cancel is a callback returned by Acquire() that signals the immediate release of rate resources. This function must only be called when no riot API method was invoked following Acquire().
type Done ¶
Done is a callback returned by Acquire() that signals the end of an API method call. Calling Done will schedule the rate to be added back to the pool at the appropriate time.
If the given response is non-nil, then Done() will parse the response headers for rate-limiting information and update configured limits. If the response indicates a rate violation, then Done will require the indicated sleep time until resources can be reserved again.
type Invocation ¶
type Invocation struct { // ApplicationKey is any unique application identifier, typically the Riot // API key provided by the Riot developer portal. ApplicationKey string // Region is the region for which the method is called. Limits are enforced // on a by-region basis. Region string // Method is the relative method path with all options stripped. For example, // a valid method is "/lol/match/v4/matches". Method string // Uniquifier is an optional token that helps make the Invocation unique. In // almost all instances, the Method is sufficient as a uniquifier, so this can // be left as the empty string. However, for the match API, getting // matchlists by account and getting recent matchlists by account have the same // underlying method with different path arguments. The Uniquifier field // allows the methods to be considered as separate invocations. Uniquifier string // NoAppQuota is true if the invocation doesn't take up appliation quota. The // default false value is typical for most invocations, which do in fact use // app quota. NoAppQuota bool }
Invocation represents a specific application's invocation of the Riot API.
func (Invocation) App ¶
func (i Invocation) App() Invocation
App returns an invocation that is application-level as opposed to method-level. It is used to track global quota.
type Limiter ¶
type Limiter interface { // Acquire blocks until all configured limits for the invocation are // satisfied, or until the context is cancelled. Once acquired, the rate // resource is reserved until Done() or Cancel() are called and return nil. Acquire(ctx context.Context, inv Invocation) (Done, Cancel, error) }
Limiter brokers access to rate resources.
Directories ¶
Path | Synopsis |
---|---|
service
|
|
client
Package client implements rate limiting by connecting to a centralized rate limiting server.
|
Package client implements rate limiting by connecting to a centralized rate limiting server. |
server
Package server defines a rate limit server.
|
Package server defines a rate limit server. |
server/ratelimit_server
Launches a ratelimit server on the specified port.
|
Launches a ratelimit server on the specified port. |