Documentation
¶
Index ¶
- func APICORS() fiber.Handler
- func APICompression() fiber.Handler
- func APILogger() fiber.Handler
- func APIRecovery() fiber.Handler
- func APISecurity() fiber.Handler
- func AccessLogger() fiber.Handler
- func ApplyRateLimits(config RateLimitConfig) []fiber.Handler
- func Brotli() fiber.Handler
- func CORS(config ...CORSConfig) fiber.Handler
- func CSRFMetaTag(ctx *fiber.Ctx) string
- func CSRFMiddleware(config ...CSRFConfig) fiber.Handler
- func CSRFTokenField(ctx *fiber.Ctx) string
- func CacheControl(maxAge time.Duration, public bool) fiber.Handler
- func Compression(config ...CompressionConfig) fiber.Handler
- func ConditionalCompression(config CompressionConfig) fiber.Handler
- func CustomLogger(format string, output *os.File) fiber.Handler
- func CustomRecovery(errorHandler func(*fiber.Ctx, error) error) fiber.Handler
- func Deflate() fiber.Handler
- func DevelopmentCORS() fiber.Handler
- func DevelopmentLogger() fiber.Handler
- func DevelopmentRecovery() fiber.Handler
- func DevelopmentSecurity() fiber.Handler
- func ETag() fiber.Handler
- func ErrorLogger() fiber.Handler
- func GetCSRFToken(ctx *fiber.Ctx) string
- func GetRequestID(c *fiber.Ctx) string
- func GetSessionID(c *fiber.Ctx) (string, bool)
- func GetUserEmail(c *fiber.Ctx) (string, bool)
- func GetUserID(c *fiber.Ctx) (string, bool)
- func GetUserRoles(c *fiber.Ctx) ([]string, bool)
- func Gzip() fiber.Handler
- func HasAnyRole(c *fiber.Ctx, roles ...string) bool
- func HasRole(c *fiber.Ctx, role string) bool
- func Helmet() fiber.Handler
- func IsAuthenticated(c *fiber.Ctx) bool
- func Logger(config ...LoggerConfig) fiber.Handler
- func NoCache() fiber.Handler
- func ProductionCORS(allowedOrigins []string) fiber.Handler
- func ProductionLogger() fiber.Handler
- func ProductionRecovery() fiber.Handler
- func ProductionSecurity() fiber.Handler
- func RateLimit(config ...RateLimiterConfig) fiber.Handler
- func RateLimitByIP(max int, expiration time.Duration) fiber.Handler
- func RateLimitByRoute(max int, expiration time.Duration) fiber.Handler
- func RateLimitByUser(max int, expiration time.Duration) fiber.Handler
- func Recovery(config ...RecoveryConfig) fiber.Handler
- func RequestID(config ...RequestIDConfig) fiber.Handler
- func RequestIDFromHeader(headerName string) fiber.Handler
- func RequestIDWithPrefix(prefix string) fiber.Handler
- func RequireAPIKey() fiber.Handler
- func RequireAnyPermission(permissions ...string) fiber.Handler
- func RequireAnyRole(roles ...string) fiber.Handler
- func RequireAuth() fiber.Handler
- func RequireGuest() fiber.Handler
- func RequireIP(allowedIPs ...string) fiber.Handler
- func RequireIPRange(allowedRanges ...string) fiber.Handler
- func RequirePermission(permission string) fiber.Handler
- func RequireRole(role string) fiber.Handler
- func RequireVerified() fiber.Handler
- func Security(config ...SecurityConfig) fiber.Handler
- func SessionClear(ctx *fiber.Ctx)
- func SessionDelete(ctx *fiber.Ctx, key string)
- func SessionDestroy(ctx *fiber.Ctx)
- func SessionGet(ctx *fiber.Ctx, key string) (interface{}, bool)
- func SessionMiddleware(config ...SessionConfig) fiber.Handler
- func SessionSet(ctx *fiber.Ctx, key string, value interface{})
- func SetRequestID(c *fiber.Ctx, requestID string)
- func ShortRequestID() fiber.Handler
- func UUIDRequestID() fiber.Handler
- func Vary(headers ...string) fiber.Handler
- func WebCORS(allowedOrigins []string) fiber.Handler
- func WebCompression() fiber.Handler
- func WebLogger() fiber.Handler
- func WebRecovery() fiber.Handler
- func WebSecurity() fiber.Handler
- type AuthMiddleware
- func (a *AuthMiddleware) OptionalAuth() fiber.Handler
- func (a *AuthMiddleware) RequireAnyRole(roles ...string) fiber.Handler
- func (a *AuthMiddleware) RequireAuth() fiber.Handler
- func (a *AuthMiddleware) RequirePermission(permission string) fiber.Handler
- func (a *AuthMiddleware) RequireRole(role string) fiber.Handler
- type CORSConfig
- type CSRF
- type CSRFConfig
- type CompressionConfig
- type Guard
- func (g *Guard) RequireAPIKey() fiber.Handler
- func (g *Guard) RequireAnyPermission(permissions ...string) fiber.Handler
- func (g *Guard) RequireAnyRole(roles ...string) fiber.Handler
- func (g *Guard) RequireAuth() fiber.Handler
- func (g *Guard) RequireGuest() fiber.Handler
- func (g *Guard) RequireIP(allowedIPs ...string) fiber.Handler
- func (g *Guard) RequireIPRange(allowedRanges ...string) fiber.Handler
- func (g *Guard) RequirePermission(permission string) fiber.Handler
- func (g *Guard) RequireRole(role string) fiber.Handler
- func (g *Guard) RequireVerified() fiber.Handler
- type GuardConfig
- type LoggerConfig
- type MemoryStore
- type MiddlewareConfig
- type MiddlewareStack
- func APIStack() *MiddlewareStack
- func AuthStack() *MiddlewareStack
- func ConfiguredStack(config MiddlewareConfig) *MiddlewareStack
- func CustomStack(middlewares ...fiber.Handler) *MiddlewareStack
- func DefaultStack() *MiddlewareStack
- func DevelopmentStack() *MiddlewareStack
- func GetStackForEnvironment(env string) *MiddlewareStack
- func NewMiddlewareStack() *MiddlewareStack
- func ProductionStack() *MiddlewareStack
- func RateLimitedStack() *MiddlewareStack
- func SecureStack() *MiddlewareStack
- func WebStack() *MiddlewareStack
- type RateLimitConfig
- type RateLimiter
- type RateLimiterConfig
- type RecoveryConfig
- type RedisRateLimiter
- type RequestIDConfig
- type SecurityConfig
- type Session
- type SessionConfig
- type SessionManager
- type SessionStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APICompression ¶
APICompression creates a compression middleware optimized for API responses
func APIRecovery ¶
APIRecovery creates a recovery middleware for API endpoints
func APISecurity ¶
APISecurity creates a security middleware for API endpoints
func AccessLogger ¶
AccessLogger creates a logger middleware for access logs
func ApplyRateLimits ¶
func ApplyRateLimits(config RateLimitConfig) []fiber.Handler
ApplyRateLimits applies multiple rate limits
func CSRFMetaTag ¶
CSRFMetaTag generates a meta tag for CSRF token
func CSRFMiddleware ¶
func CSRFMiddleware(config ...CSRFConfig) fiber.Handler
CSRFMiddleware creates a CSRF middleware with default configuration
func CSRFTokenField ¶
CSRFTokenField generates a hidden input field for CSRF token
func CacheControl ¶
CacheControl creates a cache control middleware
func Compression ¶
func Compression(config ...CompressionConfig) fiber.Handler
Compression creates a compression middleware
func ConditionalCompression ¶
func ConditionalCompression(config CompressionConfig) fiber.Handler
ConditionalCompression creates a compression middleware with path exclusions
func CustomLogger ¶
CustomLogger creates a logger middleware with custom configuration
func CustomRecovery ¶
CustomRecovery creates a recovery middleware with custom error handler
func DevelopmentCORS ¶
DevelopmentCORS creates a CORS middleware for development
func DevelopmentLogger ¶
DevelopmentLogger creates a logger middleware for development
func DevelopmentRecovery ¶
DevelopmentRecovery creates a recovery middleware for development
func DevelopmentSecurity ¶
DevelopmentSecurity creates a security middleware for development
func ErrorLogger ¶
ErrorLogger creates a logger middleware that only logs errors
func GetCSRFToken ¶
GetCSRFToken retrieves the CSRF token from context
func GetRequestID ¶
GetRequestID retrieves the request ID from context
func GetSessionID ¶
GetSessionID gets the session ID from context
func GetUserEmail ¶
GetUserEmail gets the user email from context
func GetUserRoles ¶
GetUserRoles gets the user roles from context
func HasAnyRole ¶
HasAnyRole checks if the user has any of the specified roles
func IsAuthenticated ¶
IsAuthenticated checks if the user is authenticated
func ProductionCORS ¶
ProductionCORS creates a CORS middleware for production
func ProductionLogger ¶
ProductionLogger creates a logger middleware for production
func ProductionRecovery ¶
ProductionRecovery creates a recovery middleware for production
func ProductionSecurity ¶
ProductionSecurity creates a security middleware for production
func RateLimit ¶
func RateLimit(config ...RateLimiterConfig) fiber.Handler
RateLimit creates a rate limiting middleware
func RateLimitByIP ¶
RateLimitByIP creates a rate limiter that limits by IP address
func RateLimitByRoute ¶
RateLimitByRoute creates a rate limiter that limits by route
func RateLimitByUser ¶
RateLimitByUser creates a rate limiter that limits by user ID
func Recovery ¶
func Recovery(config ...RecoveryConfig) fiber.Handler
Recovery creates a recovery middleware
func RequestID ¶
func RequestID(config ...RequestIDConfig) fiber.Handler
RequestID creates a request ID middleware
func RequestIDFromHeader ¶
RequestIDFromHeader creates a request ID middleware that uses existing header
func RequestIDWithPrefix ¶
RequestIDWithPrefix creates a request ID middleware with a prefix
func RequireAPIKey ¶
func RequireAnyPermission ¶
func RequireAnyRole ¶
func RequireGuest ¶
func RequireIPRange ¶
func RequirePermission ¶
func RequireRole ¶
func RequireVerified ¶
func Security ¶
func Security(config ...SecurityConfig) fiber.Handler
Security creates a security middleware
func SessionClear ¶
func SessionDelete ¶
func SessionDestroy ¶
func SessionMiddleware ¶
func SessionMiddleware(config ...SessionConfig) fiber.Handler
SessionMiddleware creates a session middleware with default configuration
func SessionSet ¶
func SetRequestID ¶
SetRequestID sets a custom request ID in context
func ShortRequestID ¶
ShortRequestID creates a request ID middleware that generates short IDs
func UUIDRequestID ¶
UUIDRequestID creates a request ID middleware that generates UUID-style IDs
func WebCompression ¶
WebCompression creates a compression middleware optimized for web content
func WebRecovery ¶
WebRecovery creates a recovery middleware for web endpoints
func WebSecurity ¶
WebSecurity creates a security middleware for web endpoints
Types ¶
type AuthMiddleware ¶
type AuthMiddleware struct {
// contains filtered or unexported fields
}
AuthMiddleware handles authentication
func NewAuthMiddleware ¶
func NewAuthMiddleware(jwtManager *auth.JWTManager) *AuthMiddleware
NewAuthMiddleware creates a new auth middleware
func (*AuthMiddleware) OptionalAuth ¶
func (a *AuthMiddleware) OptionalAuth() fiber.Handler
OptionalAuth middleware that adds user info to context if authenticated
func (*AuthMiddleware) RequireAnyRole ¶
func (a *AuthMiddleware) RequireAnyRole(roles ...string) fiber.Handler
RequireAnyRole middleware that requires any of the specified roles
func (*AuthMiddleware) RequireAuth ¶
func (a *AuthMiddleware) RequireAuth() fiber.Handler
RequireAuth middleware that requires authentication
func (*AuthMiddleware) RequirePermission ¶
func (a *AuthMiddleware) RequirePermission(permission string) fiber.Handler
RequirePermission middleware that requires a specific permission
func (*AuthMiddleware) RequireRole ¶
func (a *AuthMiddleware) RequireRole(role string) fiber.Handler
RequireRole middleware that requires a specific role
type CORSConfig ¶
type CORSConfig struct {
AllowOrigins []string // Allowed origins
AllowMethods []string // Allowed HTTP methods
AllowHeaders []string // Allowed headers
ExposeHeaders []string // Headers to expose to client
AllowCredentials bool // Allow credentials
MaxAge int // Max age for preflight requests
}
CORSConfig holds configuration for CORS middleware
func DefaultCORSConfig ¶
func DefaultCORSConfig() CORSConfig
DefaultCORSConfig returns default CORS configuration
type CSRF ¶
type CSRF struct {
// contains filtered or unexported fields
}
CSRF implements CSRF protection middleware
type CSRFConfig ¶
type CSRFConfig struct {
TokenLength int // Length of CSRF token
TokenName string // Name of the token in form/header
CookieName string // Name of the cookie to store token
CookiePath string // Path for the cookie
CookieDomain string // Domain for the cookie
CookieSecure bool // Secure flag for cookie
CookieHTTPOnly bool // HTTPOnly flag for cookie
CookieSameSite string // SameSite attribute for cookie
Expiration time.Duration // Token expiration time
HeaderName string // Header name for token
ErrorHandler func(*fiber.Ctx, error) error // Error handler
}
CSRFConfig holds configuration for CSRF middleware
func DefaultCSRFConfig ¶
func DefaultCSRFConfig() CSRFConfig
DefaultCSRFConfig returns default CSRF configuration
type CompressionConfig ¶
type CompressionConfig struct {
Level int // Compression level (1-9)
Types []string // Content types to compress
MinSize int // Minimum size to compress
Excluded []string // Excluded paths
}
CompressionConfig holds configuration for compression middleware
func DefaultCompressionConfig ¶
func DefaultCompressionConfig() CompressionConfig
DefaultCompressionConfig returns default compression configuration
type Guard ¶
type Guard struct {
// contains filtered or unexported fields
}
Guard implements role-based access control middleware
func NewGuard ¶
func NewGuard(config ...GuardConfig) *Guard
NewGuard creates a guard middleware with default configuration
func NewGuardMiddleware ¶
func NewGuardMiddleware(config GuardConfig) *Guard
NewGuardMiddleware creates a new guard middleware
func (*Guard) RequireAPIKey ¶
RequireAPIKey requires valid API key
func (*Guard) RequireAnyPermission ¶
RequireAnyPermission requires user to have any of the specified permissions
func (*Guard) RequireAnyRole ¶
RequireAnyRole requires user to have any of the specified roles
func (*Guard) RequireAuth ¶
RequireAuth requires user to be authenticated
func (*Guard) RequireGuest ¶
RequireGuest requires user to be a guest (not authenticated)
func (*Guard) RequireIPRange ¶
RequireIPRange allows access only from specific IP ranges
func (*Guard) RequirePermission ¶
RequirePermission requires user to have specific permission
func (*Guard) RequireRole ¶
RequireRole requires user to have specific role
func (*Guard) RequireVerified ¶
RequireVerified requires user to be verified
type GuardConfig ¶
type GuardConfig struct {
ErrorHandler func(*fiber.Ctx, error) error // Error handler for unauthorized access
UserKey string // Key to retrieve user from context
RoleKey string // Key to retrieve user role from context
}
GuardConfig holds configuration for guard middleware
func DefaultGuardConfig ¶
func DefaultGuardConfig() GuardConfig
DefaultGuardConfig returns default guard configuration
type LoggerConfig ¶
type LoggerConfig struct {
Format string // Log format
TimeFormat string // Time format
TimeZone string // Time zone
Output *os.File // Output destination
SkipPaths []string // Paths to skip logging
SkipFunc func(*fiber.Ctx) bool // Function to determine if request should be skipped
}
LoggerConfig holds configuration for logger middleware
func DefaultLoggerConfig ¶
func DefaultLoggerConfig() LoggerConfig
DefaultLoggerConfig returns default logger configuration
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore implements SessionStore using in-memory storage
func (*MemoryStore) Cleanup ¶
func (ms *MemoryStore) Cleanup() error
Cleanup removes expired sessions
func (*MemoryStore) Delete ¶
func (ms *MemoryStore) Delete(sessionID string) error
Delete removes a session
type MiddlewareConfig ¶
type MiddlewareConfig struct {
Environment string
EnableCORS bool
EnableCSRF bool
EnableSession bool
EnableRateLimit bool
EnableCompression bool
EnableSecurity bool
EnableLogging bool
EnableRecovery bool
EnableRequestID bool
}
Middleware configuration helpers
type MiddlewareStack ¶
type MiddlewareStack struct {
// contains filtered or unexported fields
}
MiddlewareStack represents a collection of middleware
func AuthStack ¶
func AuthStack() *MiddlewareStack
AuthStack returns the authentication middleware stack
func ConfiguredStack ¶
func ConfiguredStack(config MiddlewareConfig) *MiddlewareStack
ConfiguredStack creates a middleware stack based on configuration
func CustomStack ¶
func CustomStack(middlewares ...fiber.Handler) *MiddlewareStack
CustomStack creates a custom middleware stack
func DefaultStack ¶
func DefaultStack() *MiddlewareStack
DefaultStack returns the default middleware stack
func DevelopmentStack ¶
func DevelopmentStack() *MiddlewareStack
DevelopmentStack returns the development middleware stack
func GetStackForEnvironment ¶
func GetStackForEnvironment(env string) *MiddlewareStack
Environment-specific middleware stacks
func NewMiddlewareStack ¶
func NewMiddlewareStack() *MiddlewareStack
NewMiddlewareStack creates a new middleware stack
func ProductionStack ¶
func ProductionStack() *MiddlewareStack
ProductionStack returns the production middleware stack
func RateLimitedStack ¶
func RateLimitedStack() *MiddlewareStack
RateLimitedStack returns a rate-limited middleware stack
func SecureStack ¶
func SecureStack() *MiddlewareStack
SecureStack returns a highly secure middleware stack
func (*MiddlewareStack) Add ¶
func (ms *MiddlewareStack) Add(middleware fiber.Handler) *MiddlewareStack
Add adds a middleware to the stack
func (*MiddlewareStack) Apply ¶
func (ms *MiddlewareStack) Apply(app *fiber.App)
Apply applies all middleware to the app
func (*MiddlewareStack) ApplyToGroup ¶
func (ms *MiddlewareStack) ApplyToGroup(group fiber.Router)
ApplyToGroup applies all middleware to a group
type RateLimitConfig ¶
type RateLimitConfig struct {
Global RateLimiterConfig // Global rate limit
PerIP RateLimiterConfig // Per IP rate limit
PerUser RateLimiterConfig // Per user rate limit
PerRoute RateLimiterConfig // Per route rate limit
}
RateLimitConfig holds configuration for different rate limit types
func DefaultRateLimitConfig ¶
func DefaultRateLimitConfig() RateLimitConfig
DefaultRateLimitConfig returns default rate limit configuration
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements rate limiting using sliding window
func NewRateLimiter ¶
func NewRateLimiter(config RateLimiterConfig) *RateLimiter
NewRateLimiter creates a new rate limiter
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(key string) bool
Allow checks if a request is allowed
type RateLimiterConfig ¶
type RateLimiterConfig struct {
Max int // Maximum number of requests
Expiration time.Duration // Time window for rate limiting
KeyFunc func(*fiber.Ctx) string // Function to generate rate limit key
Message string // Error message when rate limit exceeded
StatusCode int // HTTP status code when rate limit exceeded
}
RateLimiterConfig holds configuration for rate limiting
func DefaultRateLimiterConfig ¶
func DefaultRateLimiterConfig() RateLimiterConfig
DefaultRateLimiterConfig returns default configuration
type RecoveryConfig ¶
type RecoveryConfig struct {
EnableStackTrace bool // Enable stack trace in response
StackTraceSize int // Stack trace size limit
ErrorHandler func(*fiber.Ctx, error) error // Custom error handler
}
RecoveryConfig holds configuration for recovery middleware
func DefaultRecoveryConfig ¶
func DefaultRecoveryConfig() RecoveryConfig
DefaultRecoveryConfig returns default recovery configuration
type RedisRateLimiter ¶
type RedisRateLimiter struct {
// This would be implemented with Redis client
// For now, we'll use the in-memory implementation
*RateLimiter
}
RedisRateLimiter implements rate limiting using Redis (for distributed systems)
func NewRedisRateLimiter ¶
func NewRedisRateLimiter(config RateLimiterConfig) *RedisRateLimiter
NewRedisRateLimiter creates a new Redis-based rate limiter
type RequestIDConfig ¶
type RequestIDConfig struct {
Header string // Header name for request ID
Generator func() string // Function to generate request ID
ContextKey string // Key to store request ID in context
}
RequestIDConfig holds configuration for request ID middleware
func DefaultRequestIDConfig ¶
func DefaultRequestIDConfig() RequestIDConfig
DefaultRequestIDConfig returns default request ID configuration
type SecurityConfig ¶
type SecurityConfig struct {
XSSProtection bool // XSS Protection header
ContentTypeNosniff bool // Content Type No Sniff header
XFrameOptions string // X-Frame-Options header value
XContentTypeOptions bool // X-Content-Type-Options header
ReferrerPolicy string // Referrer-Policy header value
PermissionsPolicy string // Permissions-Policy header value
StrictTransportSecurity string // Strict-Transport-Security header value
ContentSecurityPolicy string // Content-Security-Policy header value
ExpectCT string // Expect-CT header value
CrossOriginEmbedderPolicy string // Cross-Origin-Embedder-Policy header value
CrossOriginOpenerPolicy string // Cross-Origin-Opener-Policy header value
CrossOriginResourcePolicy string // Cross-Origin-Resource-Policy header value
}
SecurityConfig holds configuration for security middleware
func DefaultSecurityConfig ¶
func DefaultSecurityConfig() SecurityConfig
DefaultSecurityConfig returns default security configuration
type Session ¶
type Session struct {
ID string `json:"id"`
Data map[string]interface{} `json:"data"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ExpiresAt time.Time `json:"expires_at"`
}
Session represents a user session
func GetSession ¶
GetSession retrieves the session from context
func NewSession ¶
NewSession creates a new session
type SessionConfig ¶
type SessionConfig struct {
Name string // Session cookie name
Secret string // Secret key for session encryption
CookiePath string // Path for the cookie
CookieDomain string // Domain for the cookie
CookieSecure bool // Secure flag for cookie
CookieHTTPOnly bool // HTTPOnly flag for cookie
CookieSameSite string // SameSite attribute for cookie
Expiration time.Duration // Session expiration time
CleanupInterval time.Duration // Interval for cleaning up expired sessions
Store SessionStore // Session store implementation
}
SessionConfig holds configuration for session middleware
func DefaultSessionConfig ¶
func DefaultSessionConfig() SessionConfig
DefaultSessionConfig returns default session configuration
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager manages sessions
func NewSessionManager ¶
func NewSessionManager(config SessionConfig) *SessionManager
NewSessionManager creates a new session manager
func (*SessionManager) Handler ¶
func (sm *SessionManager) Handler() fiber.Handler
Handler returns the session middleware handler