Documentation ¶
Index ¶
- Constants
- func Policy(quota *Quota, options ...*Options) func(resp http.ResponseWriter, req *http.Request)
- type FreshnessInformer
- type KeyValueStorer
- type MapStore
- func (s *MapStore) Clean()
- func (s *MapStore) CleanEvery(cleaningPeriod time.Duration)
- func (s *MapStore) Delete(key string)
- func (s *MapStore) Get(key string) (value []byte, err error)
- func (s *MapStore) Read(key string) (FreshnessInformer, error)
- func (s *MapStore) Set(key string, value []byte) error
- type MapStoreError
- type MapStoreOptions
- type Options
- type Quota
Constants ¶
const (
// Too Many Requests According to http://tools.ietf.org/html/rfc6585#page-3
StatusTooManyRequests = 429
)
Variables ¶
This section is empty.
Functions ¶
func Policy ¶
A throttling Policy Takes two arguments, one required: First is a Quota (A Limit with an associated time). When the given Limit of requests is reached by a user within the given time window, access to access to resources will be denied to this user Second is Options to use with this policy. For further information on options, see Options further above.
Types ¶
type FreshnessInformer ¶
type FreshnessInformer interface {
IsFresh() bool
}
type KeyValueStorer ¶
type KeyValueStorer interface { // Simple Get Function Get(key string) ([]byte, error) // Simple Set Function Set(key string, value []byte) error }
KeyValueStorer is the required interface for the Store Option This should allow for either drop-in replacement with compatible libraries, or easy write-up of adapters
type MapStore ¶
A very simple implementation of a key value store (a concurrent safe map)
func NewMapStore ¶
func NewMapStore(binding FreshnessInformer, options ...*MapStoreOptions) *MapStore
Returns a simple key value store
func (*MapStore) CleanEvery ¶
Simple cleanup mechanism, cleaning the store every 15 minutes
type MapStoreOptions ¶
type Options ¶
type Options struct { // The status code to be returned for throttled requests // Defaults to 429 Too Many Requests StatusCode int // The message to be returned as the body of throttled requests Message string // The function used to identify the requester // Defaults to IP identification IdentificationFunction func(*http.Request) string // The key prefix to use in any key value store // defaults to "throttle" KeyPrefix string // The store to use // defaults to a simple concurrent-safe map[string]string Store KeyValueStorer // If the throttle is disabled or not // defaults to false Disabled bool }