Documentation
¶
Index ¶
- Constants
- func ErrorHandler() gin.HandlerFunc
- func Logger(log *logrus.Logger) gin.HandlerFunc
- func RequestIDMiddleware(baseLogger *zap.Logger) gin.HandlerFunc
- func RequireMasterToken(masterToken string) gin.HandlerFunc
- func TokenAuth() gin.HandlerFunc
- func TokenAuthWithLogger(logger *zap.Logger) gin.HandlerFunc
- type AuthError
- type ErrorResponse
- type NotFoundError
- type RateLimitError
- type RateLimiter
- type RateLimiterOption
- type ValidationError
Constants ¶
const LoggerKey = "logger"
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 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