modulepackage
0.0.0-20231204194614-cc8d401f70ab
Repository: https://github.com/hashicorp/go-rate.git
Documentation: pkg.go.dev
# README
Go-Rate - Go library for applying rate limits
# Packages
Package metric provides interfaces for the types of metrics that the rate.Limiter can use to aid in monitoring the limiter.
# Functions
NewLimiter will create a Limiter with the provided limits and max size.
WithNumberBuckets is used to set the number of buckets created for the quota store.
WithPolicyHeader is used to set the header key used by the Limiter for reporting the limit policy.
WithQuotaStorageCapacityMetric is used to provide a metric that will record the total capacity available to the Limiter for storing Quotas.
WithQuotaStorageUsageMetric is used to provide a metric that will record the current number of Quotas that are being stored by the Limiter.
WithUsageHeader is used to set the header key used by the Limiter for reporting quota usage.
# Constants
DefaultNumberBuckets is the default number of buckets created for the quota store.
DefaultPolicyHeader is the default HTTP header for reporting the rate limit policy.
DefaultUsageHeader is the default HTTP header for reporting quota usage.
LimitPerAuthToken indicates that the limit applies per auth token.
LimitPerIPAddress indicates that the limit applies per IP address.
LimitPerTotal indicates that the limit applies for all IP address and all Auth Tokens.
# Variables
ErrAllUnlimited is returned by NewLimiter when all of the provided Limits are Unlimited.
ErrDuplicateLimit is returned by NewLimiter when it is provided duplicate limits.
ErrEmptyLimits is returned by NewLimiter when no limits are provided.
ErrInvalidLimit is returned by NewLimiter when a limit is not valid.
ErrInvalidLimitPer is returned by Limit.validate when a Limit has a invalid LimitPer.
ErrInvalidLimitPolicy is returned by NewLimiter when a valid limit policy could not be created from the provided limits.
ErrInvalidMaxSize is returned by NewLimiter when provided an invalid max size.
ErrInvalidNumberBuckets is returned by NewLimiter when an invalid number of buckets is provided.
ErrInvalidParameter represents an invalid parameter error.
ErrLimitNotFound is returned by Limiter.Allow when a limit could not be found for a given resource+action.
ErrLimitPolicyNotFound is returned by a Limiter when a limit policy could not be found for a given resource+action.
ErrStopped is returned by Limiter.Allow if the limiter has been stopped and cannot return a quota.
NopLimiter can be used in the place of a Limiter when no limits need to be enforced, but a Limiter is expected.
# Structs
ErrLimiterFull is returned by Limiter.Allow when the limiter cannot store any additional quotas.
Limited is a Limit that defines the maximum number of requests that can be made in a given time period.
Limiter is used to determine if a request for a given resource and action should be allowed.
Quota tracks the remaining number of requests that can be made within a time period.
Unlimited is a Limit that allows an unlimited number of requests.
# Interfaces
Limit defines the number of requests that can be made to perform an action against a resource in a time period, allocated per IP address, auth token, or in total.