middleware

package
v0.0.0-...-ce3407c Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const LoggerKey = "logger"
View Source
const RequestIDKey = "request_id"

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler() gin.HandlerFunc

ErrorHandler is a middleware that handles errors in a centralized way

func Logger

func Logger(log *logrus.Logger) gin.HandlerFunc

Logger returns a middleware that logs requests using logrus

func RequestIDMiddleware

func RequestIDMiddleware(baseLogger *zap.Logger) gin.HandlerFunc

RequestIDMiddleware injects a request ID into the context and logger for each request

func RequireMasterToken

func RequireMasterToken(masterToken string) gin.HandlerFunc

RequireMasterToken is a middleware that requires a master token

func TokenAuth

func TokenAuth() gin.HandlerFunc

TokenAuth is a middleware that validates JWT tokens and gets the logger from the context

func TokenAuthWithLogger

func TokenAuthWithLogger(logger *zap.Logger) gin.HandlerFunc

TokenAuthWithLogger is a middleware that validates JWT tokens with an explicitly provided logger

Types

type AuthError

type AuthError struct {
	Message string
}

func (*AuthError) Error

func (e *AuthError) Error() string

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse represents the standard error response format

type NotFoundError

type NotFoundError struct {
	Message string
}

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type RateLimitError

type RateLimitError struct {
	Message string
}

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type RateLimiter

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

RateLimiter implements a token bucket algorithm using Redis

func NewRateLimiter

func NewRateLimiter(rdb *redis.Client, opts ...RateLimiterOption) *RateLimiter

NewRateLimiter creates a new rate limiter instance

func (*RateLimiter) RateLimit

func (rl *RateLimiter) RateLimit() gin.HandlerFunc

RateLimit returns a middleware that limits request rates using the token bucket algorithm

type RateLimiterOption

type RateLimiterOption func(*RateLimiter)

RateLimiterOption defines a function to configure RateLimiter

func WithBucketSize

func WithBucketSize(size int) RateLimiterOption

WithBucketSize sets the bucket size

func WithRefillRate

func WithRefillRate(rate int) RateLimiterOption

WithRefillRate sets the refill rate

func WithWindow

func WithWindow(seconds int) RateLimiterOption

WithWindow sets the time window in seconds

type ValidationError

type ValidationError struct {
	Message string
}

Custom error types for different error scenarios

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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