Documentation
¶
Index ¶
- Variables
- func EntrySyncInfo(e goCache.GenericCacheEntry) (currentCount int, lastSyncCount int, delta uint64)
- type Context
- type Limiter
- type LimiterStore
- func (store LimiterStore) CentralStorePeek(key string) (uint64, error)
- func (store LimiterStore) CentralStoreSync() error
- func (store LimiterStore) CentralStoreUpdates() error
- func (store LimiterStore) EntryCentralStoreExpiresIn(key string) (int64, error)
- func (store *LimiterStore) Get(ctx context.Context, key string, rate Rate) (lContext Context, err error)
- func (store *LimiterStore) Peek(ctx context.Context, key string, rate Rate) (lContext Context, err error)
- func (store *LimiterStore) StopCentralStoreUpdates() bool
- func (store LimiterStore) SyncEntryWithCentralStore(key string, opt ...Option) (updatedInMemoryCounter interface{})
- type Option
- type Rate
- type Store
- type StoreEntry
- type StoreOptions
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoCentralStore - no central store for the rate limiter was initialized ErrNoCentralStore = errors.New("no central limiter store initialized") )
Functions ¶
func EntrySyncInfo ¶
func EntrySyncInfo(e goCache.GenericCacheEntry) (currentCount int, lastSyncCount int, delta uint64)
EntrySyncInfo - delta between last sync count
Types ¶
type Context ¶
type Context struct { Limit int64 Count int64 Remaining int64 Reset int64 Reached bool Delay int64 }
Context is the limit context.
type Limiter ¶
Limiter is the limiter instance.
type LimiterStore ¶
type LimiterStore struct {
// contains filtered or unexported fields
}
LimiterStore - encapsulate the limiterStore
func NewInMemoryLimiterStore ¶
func NewInMemoryLimiterStore(maxEntries int, opt ...Option) *LimiterStore
NewInMemoryLimiterStore creates a new instance of memory store with defaults.
func (LimiterStore) CentralStorePeek ¶
CentralStorePeek - peek at a value in the distributed central store
func (LimiterStore) CentralStoreSync ¶
func (store LimiterStore) CentralStoreSync() error
CentralStoreSync - orchestrator for keeping the stores in sync that uses concurrency to get stuff done this syncs every entry, every time... see CentralStoreUpdates() which is far more efficient
func (LimiterStore) CentralStoreUpdates ¶
func (store LimiterStore) CentralStoreUpdates() error
CentralStoreUpdates is used by the janitor.Run to "do" the updates via background workers
func (LimiterStore) EntryCentralStoreExpiresIn ¶
EntryCentralStoreExpiresIn retrieves the entries TTL from the central store (if the limiter has one)
func (*LimiterStore) Get ¶
func (store *LimiterStore) Get(ctx context.Context, key string, rate Rate) (lContext Context, err error)
Get returns the limit for given identifier. (and increments the limiter's counter) if it's drifted too far from the central store, it will sync to the central store
func (*LimiterStore) Peek ¶
func (store *LimiterStore) Peek(ctx context.Context, key string, rate Rate) (lContext Context, err error)
Peek returns the limit for given identifier, without modification on current values.
func (*LimiterStore) StopCentralStoreUpdates ¶
func (store *LimiterStore) StopCentralStoreUpdates() bool
StopCentralStoreUpdates - stop the janitor
func (LimiterStore) SyncEntryWithCentralStore ¶
func (store LimiterStore) SyncEntryWithCentralStore(key string, opt ...Option) (updatedInMemoryCounter interface{})
SyncEntryWithCentralStore - figures out what to sync for one entry and sets the in memory TTL to match the central store TTL
type Option ¶
type Option func(*options)
Option - defines a func interface for passing in options to the NewInMemoryLimiterStore()
func WithLimiterExpiration ¶
WithLimiterExpSeconds sets the limiter's expiry in seconds
func WithUnsyncCounterLimit ¶
WithUnsyncCounterLimit - allows you to override the default limit to how far the in memory counter can drift from the central store
func WithUnsyncTimeLimit ¶
WithUnsyncTimeLimit - allows you to override the default time limit (milliseconds) between syncs to the central store. this cannot be 0 or it will default to defaultUnsyncTimeLimit
func WithWorkerNumber ¶
WithWorkerNumber passes an optional worker number
type Rate ¶
Rate is the rate == 1-1-S-50
func NewRateFromFormatted ¶
NewRateFromFormatted - returns the rate from the formatted version ()
type Store ¶
type Store interface { // Get increments the limit for a given identtfier and returns its context Get(ctx context.Context, key string, rate Rate) (Context, error) // Peek returns the limit for given identifier, without modification on current values. Peek(ctx context.Context, key string, rate Rate) (Context, error) // CentrailStorePeek - Peek at an entry in the central store CentralStorePeek(key string) (uint64, error) // CentralStoreSync - syncs all the keys from in memory with the central store CentralStoreSync() error // CentralStoreUpdates - just sync the updated keys from in memory with the central store CentralStoreUpdates() error // SyncEntryWithCentralStore - sync just one key from in memory with the central store and return the new entry IF it's updated SyncEntryWithCentralStore(key string, opt ...Option) interface{} // StopCentralStoreUpdates - stop all janitor syncing to central store and return whether or not the message to stop as successfully sent StopCentralStoreUpdates() bool }
Store is the common interface for limiter stores.
type StoreEntry ¶
StoreEntry - represent the entry in the store