middleware

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(required bool, db *gorm.DB, cfg *config.Config, userSvc *service.UserService) func(http.Handler) http.Handler

Auth extracts and validates JWT, attaching claims to context.

func Logging

func Logging(next http.Handler) http.Handler

Logging logs HTTP requests (method, path, status, duration). Skips static assets to reduce noise.

func ParseAndValidateToken

func ParseAndValidateToken(db *gorm.DB, tokenString string, cfg auth.Config) (*auth.Claims, error)

ParseAndValidateToken parses and validates a JWT.

func RequireRole

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

RequireRole ensures the user has one of the allowed roles. Must be used after Auth middleware.

Types

type AuthRateLimit

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

AuthRateLimit returns a middleware that limits requests per client IP for auth endpoints. Allows burst requests per window; excess receives 429 Too Many Requests.

func NewAuthRateLimit

func NewAuthRateLimit(limit int, window time.Duration) *AuthRateLimit

NewAuthRateLimit creates a rate limiter: limit requests per IP per window. Example: NewAuthRateLimit(10, time.Minute) = 10 requests per minute per IP.

func (*AuthRateLimit) Handler

func (rl *AuthRateLimit) Handler(next http.Handler) http.Handler

Handler returns middleware that returns 429 when the client IP exceeds the limit.

Jump to

Keyboard shortcuts

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