2020-09-13 11:20:11 +02:00
|
|
|
package limiter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-11-11 13:54:27 +01:00
|
|
|
// X-RateLimit-* headers
|
2020-09-13 11:20:11 +02:00
|
|
|
xRateLimitLimit = "X-RateLimit-Limit"
|
|
|
|
xRateLimitRemaining = "X-RateLimit-Remaining"
|
|
|
|
xRateLimitReset = "X-RateLimit-Reset"
|
|
|
|
)
|
|
|
|
|
2021-10-18 09:13:53 +02:00
|
|
|
type LimiterHandler interface {
|
|
|
|
New(config Config) fiber.Handler
|
|
|
|
}
|
|
|
|
|
2020-09-13 11:20:11 +02:00
|
|
|
// New creates a new middleware handler
|
|
|
|
func New(config ...Config) fiber.Handler {
|
|
|
|
// Set default config
|
2020-11-11 13:54:27 +01:00
|
|
|
cfg := configDefault(config...)
|
2020-09-13 11:20:11 +02:00
|
|
|
|
2021-10-18 09:13:53 +02:00
|
|
|
// Return the specified middleware handler.
|
|
|
|
return cfg.LimiterMiddleware.New(cfg)
|
2020-09-13 11:20:11 +02:00
|
|
|
}
|