middleware

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressMiddleware

func CompressMiddleware() fiber.Handler

CompressMiddleware enables response compression

func DefaultRateLimit

func DefaultRateLimit(config config.RateLimitConfig) fiber.Handler

DefaultRateLimit creates a default rate limiting middleware

func ErrorHandler

func ErrorHandler(c *fiber.Ctx, err error) error

func GetAPIKey

func GetAPIKey(c *fiber.Ctx) string

GetAPIKey returns the API key from the context

func GetAuthType

func GetAuthType(c *fiber.Ctx) string

GetAuthType returns the authentication type from the context

func GetUserID

func GetUserID(c *fiber.Ctx) any

GetUserID returns the user ID from the context

func GetUserPermissions

func GetUserPermissions(c *fiber.Ctx) any

GetUserPermissions returns the user permissions from the context

func GetUserRole

func GetUserRole(c *fiber.Ctx) any

GetUserRole returns the user role from the context

func Metrics

func Metrics() fiber.Handler

Metrics creates a middleware for collecting request metrics

func NewRateLimit

func NewRateLimit(config RateLimitConfig) fiber.Handler

NewRateLimit creates a rate limiting middleware with the given configuration

func PermissionRequired

func PermissionRequired(requiredPermission string) fiber.Handler

PermissionRequired creates a middleware to check user permissions

func RemoveTrailingSlash

func RemoveTrailingSlash() fiber.Handler

Middleware to remove trailing slash

func RequestID

func RequestID() fiber.Handler

RequestID creates a middleware for generating and tracking request IDs

func RequestLogger

func RequestLogger() fiber.Handler

RequestLogger creates a middleware for logging HTTP requests

func RoleRequired

func RoleRequired(allowedRoles ...string) fiber.Handler

RoleRequired creates a middleware to check user roles

func SecurityHeadersMiddleware

func SecurityHeadersMiddleware() fiber.Handler

SecurityHeadersMiddleware adds security headers

func SetupGlobalMiddleware

func SetupGlobalMiddleware(app *fiber.App, cfg *config.Config)

SetupGlobalMiddleware sets up all global middleware

Types

type RateLimitConfig

type RateLimitConfig struct {
	Window time.Duration // Time window (e.g., 1 minute)
	Limit  int64         // Maximum requests per window
}

RateLimitConfig represents the configuration for rate limiting middleware

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter represents a rate limiter implementation

func NewRateLimiter

func NewRateLimiter(config RateLimitConfig) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(clientID string) (bool, time.Time, error)

Allow checks if a client is allowed to make a request

func (*RateLimiter) Cleanup

func (rl *RateLimiter) Cleanup()

Cleanup removes expired client entries to prevent memory leaks

func (*RateLimiter) Middleware

func (rl *RateLimiter) Middleware() fiber.Handler

Middleware creates a rate limiting middleware

func (*RateLimiter) Reset

func (rl *RateLimiter) Reset()

Reset resets the rate limiter (useful for testing)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL