middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package middleware provides common HTTP middleware for HR System services. It includes authentication, logging, CORS, rate limiting, and request ID middleware.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware() gin.HandlerFunc

CORSMiddleware provides CORS support.

func RecoveryMiddleware

func RecoveryMiddleware(log logger.Logger) gin.HandlerFunc

RecoveryMiddleware provides panic recovery with logging.

func RequestIDMiddleware

func RequestIDMiddleware() gin.HandlerFunc

RequestIDMiddleware adds a unique request ID to each request.

func SecurityHeadersMiddleware

func SecurityHeadersMiddleware() gin.HandlerFunc

SecurityHeadersMiddleware adds security headers.

func TenantMiddleware

func TenantMiddleware() gin.HandlerFunc

TenantMiddleware ensures tenant isolation.

func TimeoutMiddleware

func TimeoutMiddleware(timeout time.Duration) gin.HandlerFunc

TimeoutMiddleware adds request timeout.

Types

type AuthMiddleware

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

AuthMiddleware provides JWT authentication middleware.

func NewAuthMiddleware

func NewAuthMiddleware(jwtManager auth.TokenManager, log logger.Logger) *AuthMiddleware

NewAuthMiddleware creates a new authentication middleware.

func (*AuthMiddleware) JWTAuth

func (am *AuthMiddleware) JWTAuth() gin.HandlerFunc

JWTAuth validates JWT tokens and extracts user information.

func (*AuthMiddleware) RoleRequired

func (am *AuthMiddleware) RoleRequired(requiredRole string) gin.HandlerFunc

RoleRequired checks if the user has the required role.

type LoggingMiddleware

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

LoggingMiddleware provides request/response logging.

func NewLoggingMiddleware

func NewLoggingMiddleware(log logger.Logger) *LoggingMiddleware

NewLoggingMiddleware creates a new logging middleware.

func (*LoggingMiddleware) RequestLogger

func (lm *LoggingMiddleware) RequestLogger() gin.HandlerFunc

RequestLogger logs HTTP requests and responses.

type RateLimitMiddleware

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

RateLimitMiddleware provides rate limiting functionality.

func NewRateLimitMiddleware

func NewRateLimitMiddleware(redisClient *redis.Client, log logger.Logger) *RateLimitMiddleware

NewRateLimitMiddleware creates a new rate limiting middleware.

func (*RateLimitMiddleware) RateLimit

func (rlm *RateLimitMiddleware) RateLimit(requests int, window time.Duration) gin.HandlerFunc

RateLimit applies rate limiting based on IP address.

Jump to

Keyboard shortcuts

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