middleware

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RateLimitWithWhitelist

func RateLimitWithWhitelist(rateLimiter *RateLimitMiddleware, whitelist *IPWhitelist) gin.HandlerFunc

RateLimitWithWhitelist applies rate limiting with IP whitelist bypass

func SanitizeString

func SanitizeString(input string) string

SanitizeString sanitizes a string for safe output

func ValidateResourceID

func ValidateResourceID(resourceID string) error

ValidateResourceID validates resource identifier format

Types

type AdaptiveRateLimit

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

AdaptiveRateLimit provides adaptive rate limiting based on system load

func NewAdaptiveRateLimit

func NewAdaptiveRateLimit(config RateLimitConfig, loadMonitor func() float64) *AdaptiveRateLimit

NewAdaptiveRateLimit creates an adaptive rate limiter

func (*AdaptiveRateLimit) RateLimit

func (a *AdaptiveRateLimit) RateLimit() gin.HandlerFunc

RateLimit applies adaptive rate limiting

type CSRFMiddleware

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

CSRFMiddleware provides CSRF protection

func NewCSRFMiddleware

func NewCSRFMiddleware() *CSRFMiddleware

NewCSRFMiddleware creates a new CSRF middleware

func (*CSRFMiddleware) DoubleSubmitCookie

func (m *CSRFMiddleware) DoubleSubmitCookie() gin.HandlerFunc

DoubleSubmitCookie implements double-submit cookie CSRF protection

func (*CSRFMiddleware) GenerateToken

func (m *CSRFMiddleware) GenerateToken(sessionID string) (string, error)

GenerateToken generates a new CSRF token

func (*CSRFMiddleware) GetCSRFToken

func (m *CSRFMiddleware) GetCSRFToken() gin.HandlerFunc

GetCSRFToken endpoint handler to get a new CSRF token

func (*CSRFMiddleware) ProtectCSRF

func (m *CSRFMiddleware) ProtectCSRF() gin.HandlerFunc

ProtectCSRF enforces CSRF protection on state-changing operations

func (*CSRFMiddleware) ValidateToken

func (m *CSRFMiddleware) ValidateToken(token string, sessionID string) bool

ValidateToken validates a CSRF token

type ContextKey

type ContextKey string

ContextKey for storing auth information

const (
	UserContextKey   ContextKey = "user"
	ClaimsContextKey ContextKey = "claims"
)

type EndpointLimit

type EndpointLimit struct {
	RPS   int
	Burst int
}

EndpointLimit defines limits for specific endpoints

type IPWhitelist

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

IPWhitelist provides IP whitelisting to bypass rate limits

func NewIPWhitelist

func NewIPWhitelist(ips []string) *IPWhitelist

NewIPWhitelist creates a new IP whitelist

func (*IPWhitelist) Add

func (w *IPWhitelist) Add(ip string)

Add adds an IP to the whitelist

func (*IPWhitelist) IsWhitelisted

func (w *IPWhitelist) IsWhitelisted(ip string) bool

IsWhitelisted checks if an IP is whitelisted

func (*IPWhitelist) Remove

func (w *IPWhitelist) Remove(ip string)

Remove removes an IP from the whitelist

type RateLimitConfig

type RateLimitConfig struct {
	// Global limits
	GlobalRPS   int // Requests per second globally
	GlobalBurst int // Burst size globally

	// Per-user limits
	UserRPS   int // Requests per second per user
	UserBurst int // Burst size per user

	// Per-IP limits
	IPRPS   int // Requests per second per IP
	IPBurst int // Burst size per IP

	// API key limits (higher for service accounts)
	APIKeyRPS   int // Requests per second for API keys
	APIKeyBurst int // Burst size for API keys

	// Endpoint-specific limits
	EndpointLimits map[string]EndpointLimit

	// Cleanup interval
	CleanupInterval time.Duration

	// TTL for inactive limiters
	InactiveTTL time.Duration
}

RateLimitConfig defines rate limiting configuration

func DefaultRateLimitConfig

func DefaultRateLimitConfig() RateLimitConfig

DefaultRateLimitConfig returns default rate limit configuration

type RateLimitMiddleware

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

RateLimitMiddleware provides rate limiting for API endpoints

func NewRateLimitMiddleware

func NewRateLimitMiddleware(config RateLimitConfig) *RateLimitMiddleware

NewRateLimitMiddleware creates a new rate limiting middleware

func (*RateLimitMiddleware) RateLimit

func (m *RateLimitMiddleware) RateLimit() gin.HandlerFunc

RateLimit enforces rate limiting

func (*RateLimitMiddleware) Stop

func (m *RateLimitMiddleware) Stop()

Stop stops the cleanup routine

type ValidationMiddleware

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

ValidationMiddleware provides input validation and sanitization

func NewValidationMiddleware

func NewValidationMiddleware() *ValidationMiddleware

NewValidationMiddleware creates a new validation middleware

func (*ValidationMiddleware) ValidateJSON

func (m *ValidationMiddleware) ValidateJSON(target interface{}) gin.HandlerFunc

ValidateJSON validates JSON request body against a struct

func (*ValidationMiddleware) ValidateProvider

func (m *ValidationMiddleware) ValidateProvider(provider string) error

ValidateProvider validates cloud provider name

func (*ValidationMiddleware) ValidateRegion

func (m *ValidationMiddleware) ValidateRegion(provider, region string) error

ValidateRegion validates region for a provider

func (*ValidationMiddleware) ValidateRequest

func (m *ValidationMiddleware) ValidateRequest() gin.HandlerFunc

ValidateRequest validates and sanitizes incoming requests

Jump to

Keyboard shortcuts

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