Documentation
¶
Overview ¶
Package limiter defines rate limiting systems.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store interface {
// Take takes a token from the given key if available, returning:
//
// - the configured limit size
// - the number of remaining tokens in the interval
// - the server time when new tokens will be available
// - whether the take was successful
//
// If "ok" is false, the take was unsuccessful and the caller should NOT
// service the request.
//
// See the note about keys on the interface documentation.
Take(key string) (limit, remaining, reset uint64, ok bool)
// Close terminates the store and cleans up any data structures or connections
// that may remain open. After a store is stopped, Take() should always return
// zero values.
io.Closer
}
Store is an interface for limiter storage backends.
Keys should be hash, sanitized, or otherwise scrubbed of identifiable information they will be given to the store in plaintext. If you're rate limiting by IP address, for example, the IP address would be stored in the storage system in plaintext. This may be undesirable in certain situations, like when the store is a public database. In those cases, you should hash or HMAC the key before passing giving it to the store. If you want to encrypt the value, you must use homomorphic encryption to ensure the value always encrypts to the same ciphertext.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package fasttime provides a fast clock implementation, roughly 2.5x faster than time.Now.
|
Package fasttime provides a fast clock implementation, roughly 2.5x faster than time.Now. |
|
Package httplimit provides middleware for rate limiting HTTP handlers.
|
Package httplimit provides middleware for rate limiting HTTP handlers. |
|
Package memorystore defines an in-memory storage system for limiting.
|
Package memorystore defines an in-memory storage system for limiting. |
|
Package noopstore defines a storage system for limiting that always allows requests.
|
Package noopstore defines a storage system for limiting that always allows requests. |
|
Package redisstore defines a redis-backed storage system for limiting.
|
Package redisstore defines a redis-backed storage system for limiting. |
|
tools
module
|