mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-23 02:24:27 +00:00
- Add the options to use your own middleware(should be more modular over time). - Add the Sliding window option(see #1247) - A little bit better polished version of #1247.
26 lines
525 B
Go
26 lines
525 B
Go
package limiter
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
const (
|
|
// X-RateLimit-* headers
|
|
xRateLimitLimit = "X-RateLimit-Limit"
|
|
xRateLimitRemaining = "X-RateLimit-Remaining"
|
|
xRateLimitReset = "X-RateLimit-Reset"
|
|
)
|
|
|
|
type LimiterHandler interface {
|
|
New(config Config) fiber.Handler
|
|
}
|
|
|
|
// New creates a new middleware handler
|
|
func New(config ...Config) fiber.Handler {
|
|
// Set default config
|
|
cfg := configDefault(config...)
|
|
|
|
// Return the specified middleware handler.
|
|
return cfg.LimiterMiddleware.New(cfg)
|
|
}
|