Documentation ¶
Index ¶
- Constants
- func GenerateKey(pieces ...string) string
- type PeriodType
- type RedisLimiter
- func (limiter *RedisLimiter) CheckState(ctx context.Context, key string, limitIDs ...string) (*psc.StatesByKeysWithRequest, error)
- func (limiter *RedisLimiter) CheckStates(ctx context.Context, limitIDsByKey map[string][]string) (*psc.StatesByKeysWithRequest, error)
- func (limiter *RedisLimiter) FinishRequest(ctx context.Context, requestID string, resources map[string]int64) error
- func (limiter *RedisLimiter) GetLimit(ctx context.Context, limitID string) (*psc.Limit, error)
- func (limiter *RedisLimiter) GetLimits(ctx context.Context, limitIDs []string) ([]*psc.Limit, error)
- func (limiter *RedisLimiter) GetLimitsAll(ctx context.Context) ([]*psc.Limit, error)
- func (limiter *RedisLimiter) PeekState(ctx context.Context, key string, limitIDs ...string) (*psc.StatesByKeysWithRequest, error)
- func (limiter *RedisLimiter) PeekStates(ctx context.Context, limitIDsByKey map[string][]string) (*psc.StatesByKeysWithRequest, error)
- func (limiter *RedisLimiter) RemoveLimit(ctx context.Context, limitID string) error
- func (limiter *RedisLimiter) RemoveLimits(ctx context.Context, limitIDs []string) error
- func (limiter *RedisLimiter) RemoveLimitsAll(ctx context.Context) error
- func (limiter *RedisLimiter) SetLimit(ctx context.Context, limit *psc.Limit) error
- func (limiter *RedisLimiter) SetLimits(ctx context.Context, limits []*psc.Limit) error
Constants ¶
const ( // ModeGRPC defines the gRPC mode. ModeGRPC = "grpc" // ModeHTTP defines the HTTP mode. ModeHTTP = "http" // ModeMux defines the multiplexed (gRPC + HTTP) mode. ModeMux = "mux" )
const Delimiter = ":"
Delimiter is the character used to separate pieces within a key.
Variables ¶
This section is empty.
Functions ¶
func GenerateKey ¶
GenerateKey will combine the given pieces to create a key.
Types ¶
type PeriodType ¶
type PeriodType int
PeriodType defines the periodType to rate limit.
const ( // Second defines the PeriodType per second. Second PeriodType = iota // Minute defines the PeriodType per minute. Minute // Hour defines the PeriodType per minute. Hour // Day defines the PeriodType per day. Day // Month defines the PeriodType per month. Month // Year defines the PeriodType per year. Year )
func PeriodBucketTypeToPeriodType ¶
func PeriodBucketTypeToPeriodType(periodType psc.PeriodBucketType) (PeriodType, ie.ServerError)
PeriodBucketTypeToPeriodType converts a PeriodBucketType enum to PeriodType
func StringToPeriodType ¶
func StringToPeriodType(periodType string) (PeriodType, ie.ServerError)
StringToPeriodType converts a period type to
func (PeriodType) ToFriendlyString ¶
func (periodType PeriodType) ToFriendlyString() string
ToFriendlyString converts a PeriodType to a friendly string.
func (PeriodType) ToPeroidBucketType ¶
func (periodType PeriodType) ToPeroidBucketType() psc.PeriodBucketType
ToPeroidBucketType converts a PeriodType to a PeriodBucketType.
func (PeriodType) ToString ¶
func (periodType PeriodType) ToString() string
ToString converts a PeriodType to a string.
func (PeriodType) ToTimeFormat ¶
func (periodType PeriodType) ToTimeFormat() string
ToTimeFormat will return the appropriate time format for a given PeriodType.
type RedisLimiter ¶
RedisLimiter handles rate limiting logic.
func NewRedisLimiterWithClient ¶
func NewRedisLimiterWithClient(client prd.Client) *RedisLimiter
NewRedisLimiterWithClient will return a new Limiter with a specified client.
func NewRedisLimiterWithURL ¶
func NewRedisLimiterWithURL(redisURL string) (*RedisLimiter, error)
NewRedisLimiterWithURL will create a new Limiter with the specified URL.
func (*RedisLimiter) CheckState ¶
func (limiter *RedisLimiter) CheckState(ctx context.Context, key string, limitIDs ...string) (*psc.StatesByKeysWithRequest, error)
CheckState should be called at the beginning of a irq. It will check the given rate limit inputs and return the current state. NOTE: Check will increment concurrents and throttles (if applicable).
func (*RedisLimiter) CheckStates ¶
func (limiter *RedisLimiter) CheckStates(ctx context.Context, limitIDsByKey map[string][]string) (*psc.StatesByKeysWithRequest, error)
CheckStates should be called at the beginning of a irq. It will check the given rate limit inputs and return the current state. NOTE: Check will increment concurrents and throttles (if applicable).
func (*RedisLimiter) FinishRequest ¶
func (limiter *RedisLimiter) FinishRequest(ctx context.Context, requestID string, resources map[string]int64) error
FinishRequest should be called at the end of a irq. It will decrement concurrents, increment quotas, and return the updated quota state.
func (*RedisLimiter) GetLimits ¶
func (limiter *RedisLimiter) GetLimits(ctx context.Context, limitIDs []string) ([]*psc.Limit, error)
GetLimits will get limits by their IDs.
func (*RedisLimiter) GetLimitsAll ¶
GetLimitsAll will get all limits.
func (*RedisLimiter) PeekState ¶
func (limiter *RedisLimiter) PeekState(ctx context.Context, key string, limitIDs ...string) (*psc.StatesByKeysWithRequest, error)
PeekState will get the current states for the provided key without mutation.
func (*RedisLimiter) PeekStates ¶
func (limiter *RedisLimiter) PeekStates(ctx context.Context, limitIDsByKey map[string][]string) (*psc.StatesByKeysWithRequest, error)
PeekStates will get the current states for the provided keys without mutation.
func (*RedisLimiter) RemoveLimit ¶
func (limiter *RedisLimiter) RemoveLimit(ctx context.Context, limitID string) error
RemoveLimit will remove a limit by its ID.
func (*RedisLimiter) RemoveLimits ¶
func (limiter *RedisLimiter) RemoveLimits(ctx context.Context, limitIDs []string) error
RemoveLimits will remove limits by their IDs.
func (*RedisLimiter) RemoveLimitsAll ¶
func (limiter *RedisLimiter) RemoveLimitsAll(ctx context.Context) error
RemoveLimitsAll will remove all limits.