middleware

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(authService service.AuthService) gin.HandlerFunc

AuthMiddleware creates JWT authentication middleware

func BusinessValidationMiddleware

func BusinessValidationMiddleware() gin.HandlerFunc

BusinessValidationMiddleware creates middleware for business logic validation

func CORSMiddleware

func CORSMiddleware() gin.HandlerFunc

CORSMiddleware creates CORS middleware with configurable options

func ErrorHandlerMiddleware

func ErrorHandlerMiddleware() gin.HandlerFunc

ErrorHandlerMiddleware creates error handling middleware

func GetUserFromContext

func GetUserFromContext(c *gin.Context) (*models.User, bool)

GetUserFromContext extracts user from Gin context

func GetValidatedBody

func GetValidatedBody(c *gin.Context) (interface{}, bool)

GetValidatedBody retrieves validated body from context

func GetValidatedQuery

func GetValidatedQuery(c *gin.Context) (interface{}, bool)

GetValidatedQuery retrieves validated query from context

func GlobalErrorHandler

func GlobalErrorHandler() gin.HandlerFunc

GlobalErrorHandler creates a comprehensive error handling middleware

func LoggingMiddleware

func LoggingMiddleware() gin.HandlerFunc

LoggingMiddleware creates request logging middleware

func MethodNotAllowedHandler

func MethodNotAllowedHandler() gin.HandlerFunc

MethodNotAllowedHandler handles 405 errors

func NotFoundHandler

func NotFoundHandler() gin.HandlerFunc

NotFoundHandler handles 404 errors

func OptionalAuthMiddleware

func OptionalAuthMiddleware(authService service.AuthService) gin.HandlerFunc

OptionalAuthMiddleware creates optional JWT authentication middleware This middleware will set user context if token is provided, but won't fail if not

func PanicRecoveryHandler

func PanicRecoveryHandler() gin.HandlerFunc

PanicRecoveryHandler creates a panic recovery middleware with detailed logging

func RateLimitByUserMiddleware

func RateLimitByUserMiddleware(limit int, window time.Duration) gin.HandlerFunc

RateLimitByUserMiddleware creates rate limiting middleware by authenticated user

func RateLimitMiddleware

func RateLimitMiddleware(limit int, window time.Duration) gin.HandlerFunc

RateLimitMiddleware creates rate limiting middleware

func RecoveryMiddleware

func RecoveryMiddleware() gin.HandlerFunc

RecoveryMiddleware creates panic recovery middleware

func RequestSizeLimit

func RequestSizeLimit(maxSize int64) gin.HandlerFunc

RequestSizeLimit creates middleware to limit request body size

func RequireAdmin

func RequireAdmin() gin.HandlerFunc

RequireAdmin creates admin-only authorization middleware

func RequireRole

func RequireRole(roles ...models.UserRole) gin.HandlerFunc

RequireRole creates role-based authorization middleware

func RestrictedCORSMiddleware

func RestrictedCORSMiddleware(allowedOrigins []string) gin.HandlerFunc

RestrictedCORSMiddleware creates CORS middleware with specific allowed origins

func StructuredLoggingMiddleware

func StructuredLoggingMiddleware() gin.HandlerFunc

StructuredLoggingMiddleware creates structured request logging middleware

func ValidateJSON

func ValidateJSON(obj interface{}) gin.HandlerFunc

ValidateJSON validates JSON request body

func ValidateParams

func ValidateParams(paramValidators map[string]func(string) error) gin.HandlerFunc

ValidateParams validates URL parameters

func ValidateQuery

func ValidateQuery(obj interface{}) gin.HandlerFunc

ValidateQuery validates query parameters

Types

type RateLimiter

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

RateLimiter represents a simple rate limiter

func NewRateLimiter

func NewRateLimiter(limit int, window time.Duration) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(key string) bool

Allow checks if a request should be allowed

Jump to

Keyboard shortcuts

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