middleware

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserIDKey    contextKey = "user_id"
	UserEmailKey contextKey = "user_email"
	UserRoleKey  contextKey = "user_role"
	RequestIDKey contextKey = "request_id"
)

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(cfg *config.Config) func(http.Handler) http.Handler

AuthMiddleware validates JWT tokens

func GetUserID

func GetUserID(ctx context.Context) (uuid.UUID, bool)

GetUserID retrieves the user ID from context

func GetUserRole

func GetUserRole(ctx context.Context) (string, bool)

GetUserRole retrieves the user role from context

func RequestID

func RequestID(next http.Handler) http.Handler

RequestID middleware adds a unique request ID

func RequireRole

func RequireRole(roles ...string) func(http.Handler) http.Handler

RequireRole middleware ensures the user has one of the required roles

Types

type RateLimiter

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

RateLimiter implements per-IP rate limiting

func NewRateLimiter

func NewRateLimiter(requestsPerSecond int) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) RateLimit

func (rl *RateLimiter) RateLimit(next http.Handler) http.Handler

RateLimit middleware limits requests per IP

Jump to

Keyboard shortcuts

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