Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( //ErrRateLimitExceeded Returned when a rate limit is exceeded ErrRateLimitExceeded = errors.New("Rate Limit Exceeded") //ErrInvalidID occurs when a limiter with an invalid ID is used. ErrInvalidID = errors.New("Invalid ID") )
Functions ¶
func CleanupAll ¶
CleanupAll removes all expired actions from all limiters in the database. possibly a very expensive call.
func DoMigrations ¶
DoMigrations adds the models to the database. Should be run once, if you choose to use automigrations at all.
Types ¶
type Limiter ¶
type Limiter struct { ID uint Times int Interval time.Duration // contains filtered or unexported fields }
Limiter represents the rate limiter
func NewLimiter ¶
NewLimiter Creates a new limiter with the specified arguments and saves it to the database.
func (*Limiter) Save ¶
Save allows you to update the attributes of a limiter. If you make any changes to a limiter, simply Save() it, and it will go back to the database
func (*Limiter) Take ¶
Take attempts to do an "action". if there is an error determining if an action
is possible or writing the action to the database, the returned action count will be 0. If the rate is exceeded, the total count will be returned, as well ass ErrRateLimitExceeded. If the Take is successful, it will return the number of actions and a nil error.
Click to show internal directories.
Click to hide internal directories.