middleware

package
v0.260224.1130 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MPL-2.0 Imports: 17 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

func (*AuthMiddleware) VirtualModelAuthMiddleware added in v0.260224.0

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

VirtualModelAuthMiddleware middleware for virtual model API authentication Uses an independent token separate from the main model token

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

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

MemoryLogMiddleware provides Gin middleware with memory log storage

func NewMemoryLogMiddleware

func NewMemoryLogMiddleware(maxEntries int) *MemoryLogMiddleware

NewMemoryLogMiddleware creates a new memory log middleware

func (*MemoryLogMiddleware) Clear

func (m *MemoryLogMiddleware) Clear()

Clear removes all log entries

func (*MemoryLogMiddleware) GetEntries

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

GetEntries returns all log entries in chronological order

func (*MemoryLogMiddleware) GetEntriesByLevel

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

GetEntriesByLevel returns log entries matching the specified level

func (*MemoryLogMiddleware) GetEntriesSince

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

GetEntriesSince returns log entries after the specified time

func (*MemoryLogMiddleware) GetLatest

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

GetLatest returns the newest N log entries

func (*MemoryLogMiddleware) Middleware

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

func (m *MemoryLogMiddleware) Size() int

Size returns the current number of stored log entries

Jump to

Keyboard shortcuts

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