Documentation
¶
Overview ¶
Package memory provides an in-process ratelimit.Store. It is not distributed, but is the zero-configuration default and a lightweight backend for tests.
Index ¶
- type Store
- func (s *Store) Close() error
- func (s *Store) GiveBackWindow(_ context.Context, key string) error
- func (s *Store) IncrWindow(_ context.Context, key string, window time.Duration) (int64, error)
- func (s *Store) PeekWindow(_ context.Context, key string) (int64, bool, error)
- func (s *Store) Ping(context.Context) error
- func (s *Store) TakeTokens(_ context.Context, key string, rate, burst, n int) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is an in-process Store.
func (*Store) GiveBackWindow ¶ added in v0.0.6
GiveBackWindow implements ratelimit.WindowGiver: return one count to the window, never below zero.
An entry that has already expired is left alone rather than revived: the window it counted belongs to a period that is over, and writing to it would hand the next window a negative starting point. The next IncrWindow starts a fresh entry anyway.
func (*Store) IncrWindow ¶
IncrWindow implements ratelimit.Store.
func (*Store) PeekWindow ¶ added in v0.0.6
PeekWindow implements ratelimit.WindowReader: the counter as it stands, without moving it.
An expired entry is reported as "no key" rather than as its last value: the window it belonged to is over, and the next request starts a new one. The sweep is left to the write path, so this answers from whatever the map holds and gives the same answer IncrWindow would have acted on.