Documentation ¶
Overview ¶
Package ratelimiter is a generated GoMock package.
Index ¶
Constants ¶
const ( DEFAULT_MAX_REQUESTS = 10 DEFAULT_REFRESH_INTERVAL = 1 * time.Minute )
Variables ¶
var (
ErrTooManyRequests = errors.New("max requests limit reached")
)
Functions ¶
This section is empty.
Types ¶
type Mockstore ¶
type Mockstore struct {
// contains filtered or unexported fields
}
Mockstore is a mock of store interface.
func NewMockstore ¶
func NewMockstore(ctrl *gomock.Controller) *Mockstore
NewMockstore creates a new mock instance.
func (*Mockstore) EXPECT ¶
func (m *Mockstore) EXPECT() *MockstoreMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*Mockstore) GetCounter ¶
GetCounter mocks base method.
type MockstoreMockRecorder ¶
type MockstoreMockRecorder struct {
// contains filtered or unexported fields
}
MockstoreMockRecorder is the mock recorder for Mockstore.
func (*MockstoreMockRecorder) GetCounter ¶
func (mr *MockstoreMockRecorder) GetCounter(ctx, requestKey interface{}) *gomock.Call
GetCounter indicates an expected call of GetCounter.
func (*MockstoreMockRecorder) IncreaseWithTTL ¶
func (mr *MockstoreMockRecorder) IncreaseWithTTL(ctx, requestKey, ttl interface{}) *gomock.Call
IncreaseWithTTL indicates an expected call of IncreaseWithTTL.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter represents a rate limiter
func NewRateLimiter ¶
func NewRateLimiter(store store, config RateLimiterConfig) *RateLimiter
NewRateLimiter creates a new rate limiter object
func (RateLimiter) CheckRequest ¶
func (r RateLimiter) CheckRequest(ctx context.Context, keys []string) error
CheckRequest checks if the request is allowed, returns an error when reach the max number of requests
type RateLimiterConfig ¶
RateLimiter contains the rate limiter's configuration
func (RateLimiterConfig) IsEmpty ¶
func (cfg RateLimiterConfig) IsEmpty() bool
IsEmpty checks if the configuration is empty
func (*RateLimiterConfig) SetDefault ¶
func (cfg *RateLimiterConfig) SetDefault()
SetDefault sets the default configuration (bucket default, 10 reqs/minute)
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) GetCounter ¶
GetCounter returns the counter value for the given request key