middleware

package
v0.260124.1430 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORS

func CORS() gin.HandlerFunc

CORS returns a CORS middleware handler

func CORSWithConfig

func CORSWithConfig(config CORSConfig) gin.HandlerFunc

CORSWithConfig returns a CORS middleware handler with custom configuration

Types

type AuthMiddleware

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

AuthMiddleware provides authentication middleware for different types of authentication

func NewAuthMiddleware

func NewAuthMiddleware(cfg *config.Config, jwtManager *auth.JWTManager) *AuthMiddleware

NewAuthMiddleware creates a new authentication middleware

func (*AuthMiddleware) AuthMiddleware

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

AuthMiddleware validates the authentication token

func (*AuthMiddleware) ModelAuthMiddleware

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

ModelAuthMiddleware middleware for OpenAI and Anthropic API authentication The auth will support both `Authorization` and `X-Api-Key`

func (*AuthMiddleware) UserAuthMiddleware

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

UserAuthMiddleware middleware for UI and control API authentication

type CORSConfig

type CORSConfig struct {
	AllowOrigins    string
	AllowMethods    string
	AllowHeaders    string
	ExposeHeaders   string
	MaxAge          int
	HandlePreflight bool
}

CORSConfig defines the configuration for CORS middleware

type ErrorDetail

type ErrorDetail struct {
	Message string `json:"message"`
	Type    string `json:"type"`
	Code    string `json:"code,omitempty"`
}

ErrorDetail represents error details

type ErrorLogMiddleware

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

ErrorLogMiddleware logs requests and responses to a file when debug mode is enabled

func NewErrorLogMiddleware

func NewErrorLogMiddleware(logPath string, maxSizeMB int) *ErrorLogMiddleware

NewErrorLogMiddleware creates a new debug middleware

func (*ErrorLogMiddleware) Disable

func (dm *ErrorLogMiddleware) Disable()

Disable disables debug logging

func (*ErrorLogMiddleware) Enable

func (dm *ErrorLogMiddleware) Enable() error

Enable enables debug logging

func (*ErrorLogMiddleware) IsEnabled

func (dm *ErrorLogMiddleware) IsEnabled() bool

IsEnabled returns whether debug logging is enabled

func (*ErrorLogMiddleware) Middleware

func (dm *ErrorLogMiddleware) Middleware() gin.HandlerFunc

Middleware returns the Gin middleware function

func (*ErrorLogMiddleware) SetFilterExpression

func (dm *ErrorLogMiddleware) SetFilterExpression(expression string) error

SetFilterExpression recompiles and sets a new filter expression

func (*ErrorLogMiddleware) Stop

func (dm *ErrorLogMiddleware) Stop()

Stop closes the log file

type ErrorResponse

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

ErrorResponse represents an error response

type FilterContext

type FilterContext struct {
	StatusCode int    `expr:"StatusCode"`
	Method     string `expr:"Method"`
	Path       string `expr:"Path"`
	Query      string `expr:"Query"`
}

FilterContext provides the context for filter expression evaluation

type MemoryLogMiddleware added in v0.260124.900

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

MemoryLogMiddleware provides Gin middleware with memory log storage

func NewMemoryLogMiddleware added in v0.260124.900

func NewMemoryLogMiddleware(maxEntries int) *MemoryLogMiddleware

NewMemoryLogMiddleware creates a new memory log middleware

func (*MemoryLogMiddleware) Clear added in v0.260124.900

func (m *MemoryLogMiddleware) Clear()

Clear removes all log entries

func (*MemoryLogMiddleware) GetEntries added in v0.260124.900

func (m *MemoryLogMiddleware) GetEntries() []*logrus.Entry

GetEntries returns all log entries in chronological order

func (*MemoryLogMiddleware) GetEntriesByLevel added in v0.260124.900

func (m *MemoryLogMiddleware) GetEntriesByLevel(level logrus.Level) []*logrus.Entry

GetEntriesByLevel returns log entries matching the specified level

func (*MemoryLogMiddleware) GetEntriesSince added in v0.260124.900

func (m *MemoryLogMiddleware) GetEntriesSince(since time.Time) []*logrus.Entry

GetEntriesSince returns log entries after the specified time

func (*MemoryLogMiddleware) GetLatest added in v0.260124.900

func (m *MemoryLogMiddleware) GetLatest(n int) []*logrus.Entry

GetLatest returns the newest N log entries

func (*MemoryLogMiddleware) Middleware added in v0.260124.900

func (m *MemoryLogMiddleware) Middleware() gin.HandlerFunc

Middleware returns a Gin middleware compatible with gin.Logger() It logs all HTTP requests to the memory log hook

func (*MemoryLogMiddleware) Size added in v0.260124.900

func (m *MemoryLogMiddleware) Size() int

Size returns the current number of stored log entries

type StatsMiddleware added in v0.260124.900

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

StatsMiddleware tracks usage statistics by updating service-embedded stats

func NewStatsMiddleware added in v0.260124.900

func NewStatsMiddleware(cfg *config.Config) *StatsMiddleware

NewStatsMiddleware creates a new statistics middleware

func (*StatsMiddleware) Middleware added in v0.260124.900

func (sm *StatsMiddleware) Middleware() gin.HandlerFunc

Middleware returns the Gin middleware function

func (*StatsMiddleware) RecordUsage added in v0.260124.900

func (sm *StatsMiddleware) RecordUsage(serviceID string, inputTokens, outputTokens int)

RecordUsage records usage for a service by finding it in the rules and updating its embedded stats

func (*StatsMiddleware) RecordUsageOnRule added in v0.260124.900

func (sm *StatsMiddleware) RecordUsageOnRule(rule *typ.Rule, provider, model string, inputTokens, outputTokens int)

RecordUsageOnRule records usage directly on a specific rule's services

func (*StatsMiddleware) Stop added in v0.260124.900

func (sm *StatsMiddleware) Stop()

Stop stops the cleanup routine (no-op in new architecture)

Jump to

Keyboard shortcuts

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