middleware

package
v0.0.0-...-d2ebf61 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CustomRateLimitResponse

func CustomRateLimitResponse() gin.HandlerFunc

CustomRateLimitResponse provides a custom response for rate limit exceeded

func EndpointAuthMiddleware

func EndpointAuthMiddleware(endpointService EndpointService, authService EndpointAuthService, oauthService OAuthService) gin.HandlerFunc

EndpointAuthMiddleware validates access to endpoint based on its auth settings

func EndpointCORSMiddleware

func EndpointCORSMiddleware() gin.HandlerFunc

EndpointCORSMiddleware applies CORS settings based on endpoint configuration

func EndpointLookupMiddleware

func EndpointLookupMiddleware(endpointService EndpointService) gin.HandlerFunc

EndpointLookupMiddleware resolves endpoint by name from URL

func EndpointRateLimitMiddleware

func EndpointRateLimitMiddleware() gin.HandlerFunc

EndpointRateLimitMiddleware applies rate limiting based on endpoint configuration

func GetRewriteInfo

func GetRewriteInfo(c *gin.Context) (bool, string, string)

GetRewriteInfo extracts rewrite information from Gin context

func GetServerID

func GetServerID(c *gin.Context) string

GetServerID extracts server ID from Gin context

func GetSessionID

func GetSessionID(c *gin.Context) string

GetSessionID extracts session ID from Gin context

func GetTransportContext

func GetTransportContext(c *gin.Context) *types.TransportContext

GetTransportContext extracts transport context from Gin context

func GetTransportType

func GetTransportType(c *gin.Context) types.TransportType

GetTransportType extracts transport type from Gin context

func IPRateLimit

func IPRateLimit(config *IPRateLimitConfig) gin.HandlerFunc

IPRateLimit creates IP-based rate limiting middleware

func IPRateLimitFromAppConfig

func IPRateLimitFromAppConfig(cfg *config.RateLimitConfig, redisCfg *config.RedisConfig) gin.HandlerFunc

IPRateLimitFromAppConfig creates IP-based rate limiting middleware from app config

func IPRateLimitWithMemory

func IPRateLimitWithMemory(requestsPerMin int) gin.HandlerFunc

IPRateLimitWithMemory creates IP rate limiting middleware with memory backend

func IPRateLimitWithRedis

func IPRateLimitWithRedis(requestsPerMin int, redisAddr, redisPassword string, redisDB int) gin.HandlerFunc

IPRateLimitWithRedis creates IP rate limiting middleware with Redis backend

func Recovery

func Recovery() gin.HandlerFunc

Recovery returns a middleware that recovers from panics

func RecoveryWithConfig

func RecoveryWithConfig(config *RecoveryConfig) gin.HandlerFunc

RecoveryWithConfig returns a middleware that recovers from panics with custom configuration

func RecoveryWithWriter

func RecoveryWithWriter(writer io.Writer) gin.HandlerFunc

RecoveryWithWriter returns a middleware that recovers from panics and writes to writer

func SecureHeaders

func SecureHeaders() gin.HandlerFunc

SecureHeaders is an alias for SecurityHeaders for backward compatibility

func SecureHeadersWithConfig

func SecureHeadersWithConfig(config *SecurityConfig) gin.HandlerFunc

SecureHeadersWithConfig is an alias for SecurityHeadersWithConfig for backward compatibility

func SecurityHeaders

func SecurityHeaders() gin.HandlerFunc

SecurityHeaders returns a security headers middleware with default configuration

func SecurityHeadersWithConfig

func SecurityHeadersWithConfig(config *SecurityConfig) gin.HandlerFunc

SecurityHeadersWithConfig returns a security headers middleware with custom configuration

func ServerContextMiddleware

func ServerContextMiddleware() gin.HandlerFunc

ServerContextMiddleware extracts server context from rewritten paths

func SessionIDMiddleware

func SessionIDMiddleware() gin.HandlerFunc

SessionIDMiddleware extracts or generates session IDs for stateful transports

func Timeout

func Timeout() gin.HandlerFunc

Timeout returns a middleware that times out requests

func TimeoutWithConfig

func TimeoutWithConfig(config *TimeoutConfig) gin.HandlerFunc

TimeoutWithConfig returns a middleware that times out requests with custom configuration

func TransportTypeMiddleware

func TransportTypeMiddleware() gin.HandlerFunc

TransportTypeMiddleware determines the transport type from the request

Types

type Chain

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

Chain represents a middleware chain

func AdminChain

func AdminChain() *Chain

AdminChain creates a middleware chain for admin routes

func AuthenticatedChain

func AuthenticatedChain() *Chain

AuthenticatedChain creates a middleware chain for authenticated routes

func DefaultChain

func DefaultChain() *Chain

DefaultChain creates a default middleware chain for the gateway

func DefaultChainFromConfig

func DefaultChainFromConfig(cfg *config.Config) *Chain

DefaultChainFromConfig creates a default middleware chain from app config

func DefaultChainWithAppConfig

func DefaultChainWithAppConfig(cfg *config.Config, securityConfig *SecurityConfig) *Chain

DefaultChainWithAppConfig creates a default middleware chain with app and security config

func DefaultChainWithConfig

func DefaultChainWithConfig(securityConfig *SecurityConfig) *Chain

DefaultChainWithConfig creates a default middleware chain with custom security config

func DefaultChainWithRateLimit

func DefaultChainWithRateLimit(requestsPerMin int, redisAddr, redisPassword string, redisDB int) *Chain

DefaultChainWithRateLimit creates a default middleware chain with Redis rate limiting

func NewChain

func NewChain() *Chain

NewChain creates a new middleware chain

func (*Chain) Apply

func (c *Chain) Apply(group *gin.RouterGroup)

Apply applies the middleware chain to a gin router group

func (*Chain) Build

func (c *Chain) Build() []gin.HandlerFunc

Build returns the middleware chain as a slice

func (*Chain) Use

func (c *Chain) Use(middleware gin.HandlerFunc) *Chain

Use adds middleware to the chain

type EndpointAuthService

type EndpointAuthService interface {
	ValidateAPIKey(apiKey string) (*types.APIKey, error)
	GetUserByID(userID string) (*types.User, error)
}

EndpointAuthService interface for validating API keys and OAuth tokens

type EndpointService

type EndpointService interface {
	ResolveEndpoint(ctx context.Context, name string) (*types.EndpointConfig, error)
}

EndpointService interface for endpoint operations

type IPRateLimitConfig

type IPRateLimitConfig struct {
	RedisAddr      string   `yaml:"redis_addr"`
	RedisPassword  string   `yaml:"redis_password"`
	TrustedProxies []string `yaml:"trusted_proxies"`
	SkipPaths      []string `yaml:"skip_paths"`
	CustomHeaders  []string `yaml:"custom_headers"`
	RequestsPerMin int      `yaml:"requests_per_minute"`
	BurstSize      int      `yaml:"burst_size"`
	RedisDB        int      `yaml:"redis_db"`
	Enabled        bool     `yaml:"enabled"`
	RedisEnabled   bool     `yaml:"redis_enabled"`
}

IPRateLimitConfig holds the configuration for IP rate limiting

func DefaultIPRateLimitConfig

func DefaultIPRateLimitConfig() *IPRateLimitConfig

DefaultIPRateLimitConfig returns default configuration

type OAuthService

type OAuthService interface {
	ValidateToken(ctx context.Context, bearerToken string) (*types.OAuthToken, error)
}

OAuthService interface for OAuth token validation

type PathRewriteConfig

type PathRewriteConfig struct {
	LogLevel string                  `yaml:"log_level" json:"log_level"`
	Rules    []types.PathRewriteRule `yaml:"rules" json:"rules"`
	Enabled  bool                    `yaml:"enabled" json:"enabled"`
}

PathRewriteConfig represents configuration for path rewriting

func (*PathRewriteConfig) ValidateConfig

func (c *PathRewriteConfig) ValidateConfig() error

ValidateConfig validates the path rewrite configuration

type PathRewriteMiddleware

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

PathRewriteMiddleware handles path rewriting for server-specific endpoints

func NewPathRewriteMiddleware

func NewPathRewriteMiddleware() *PathRewriteMiddleware

NewPathRewriteMiddleware creates a new path rewrite middleware

func (*PathRewriteMiddleware) AddRule

func (p *PathRewriteMiddleware) AddRule(rule types.PathRewriteRule)

AddRule adds a custom rewrite rule

func (*PathRewriteMiddleware) GetRules

GetRules returns all rewrite rules

func (*PathRewriteMiddleware) Handler

func (p *PathRewriteMiddleware) Handler() gin.HandlerFunc

Handler returns the Gin middleware handler

type RecoveryConfig

type RecoveryConfig struct {
	// LogHandler handles panic logging
	LogHandler func(c *gin.Context, err interface{}, stack []byte)

	// RecoveryHandler handles the recovery process
	RecoveryHandler func(c *gin.Context, err interface{})
}

RecoveryConfig holds recovery middleware configuration

type SecurityConfig

type SecurityConfig struct {
	CustomHeaders             map[string]string
	ContentSecurityPolicy     string
	XFrameOptions             string
	XContentTypeOptions       string
	ReferrerPolicy            string
	PermissionsPolicy         string
	StrictTransportSecurity   string
	XXSSProtection            string
	CrossOriginEmbedderPolicy string
	CrossOriginOpenerPolicy   string
	CrossOriginResourcePolicy string
}

SecurityConfig holds security headers configuration

func DefaultSecurityConfig

func DefaultSecurityConfig() *SecurityConfig

DefaultSecurityConfig returns default security headers configuration

func DevelopmentSecurityConfig

func DevelopmentSecurityConfig() *SecurityConfig

DevelopmentSecurityConfig returns security headers configuration suitable for development

type TimeoutConfig

type TimeoutConfig struct {
	TimeoutHandler func(c *gin.Context)
	PanicHandler   func(c *gin.Context, err interface{})
	Timeout        time.Duration
}

TimeoutConfig holds timeout middleware configuration

Jump to

Keyboard shortcuts

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