Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrBlacklist = errors.New("blacklisted")
)
Functions ¶
func New ¶
func New(config ...Config) pine.Middleware
Types ¶
type Config ¶
type Config struct {
// Defines the maximum number of requests a client can make within a specified time
// window
//
// Default: 5
MaxRequests int
// Defines the time window between which a client is allowed to make a request.
// If the client makes more than MaxRequests requests within this time window,
// the client will be blocked until the time window has passed.
//
// Default: 1 second
Window time.Duration
// Defines the handler that will be called when a client is blocked or rate limits
// are exceeded.
//
// Default: returns a 429 status code
Handler pine.Handler
// Defines whether or not to show the rate limit headers in the response.
//
// Default: true
ShowHeader bool
// Defines the function that will be used to generate the key for the rate limit.
// You can use the IP address of the client or you can use the user id of the user.
//
// Default: returns the IP address of the client
KeyGen func(c *pine.Ctx) string
// Defines a list of IP addresses or user ids that are allowed to make requests.
// Any IP address defined in the whitelist will be allowed to make requests beyond
// the rate limit.
//
// Default: []string{}
Whitelist []string
// Defines a list of IP addresses or user ids that are not allowed to make requests.
// IP addresses in this list will be blocked whether or not the rate limit is defined.
//
// Default: []string{}
Blacklist []string
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.