middleware

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 27 Imported by: ? 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

CooldownGlobal 全局冷却管理器;阈值/窗口采用"运行时读取 config", 数据库更新 OptionMap 后即可立即生效,不会让配置形同虚设。

Functions

func AdminAuth

func AdminAuth() func(c *gin.Context)

func CORS

func CORS() gin.HandlerFunc

func Cache

func Cache() func(c *gin.Context)

func CriticalRateLimit

func CriticalRateLimit() func(c *gin.Context)

func DefaultSkipPaths added in v1.0.1

func DefaultSkipPaths() []string

DefaultSkipPaths 返回当前默认跳过名单的副本(供诊断与验收测试使用)。

func Distribute

func Distribute() func(c *gin.Context)

func DownloadRateLimit

func DownloadRateLimit() func(c *gin.Context)

func GlobalAPIRateLimit

func GlobalAPIRateLimit() func(c *gin.Context)

func GlobalWebRateLimit

func GlobalWebRateLimit() func(c *gin.Context)

func GzipDecodeMiddleware

func GzipDecodeMiddleware() gin.HandlerFunc

func Language

func Language() gin.HandlerFunc

func RegisterDefaultSkipPath added in v1.0.1

func RegisterDefaultSkipPath(prefix string)

RegisterDefaultSkipPath 向默认跳过名单追加一条路径前缀。

仅供扩展方在 init() 期调用;须在 SetUpLogger 之前完成注册。 用户显式设置 LOG_SKIP_PATHS 时仍以显式值为准,本默认名单不生效。

func RelayPanicRecover

func RelayPanicRecover() gin.HandlerFunc

func RequestId

func RequestId() func(c *gin.Context)

func RootAuth

func RootAuth() func(c *gin.Context)

func SelectChannel

func SelectChannel(ctx context.Context, group, requestModel string, lastFailedChannelId int, userId int) (*model.Channel, string, error)

func SetUpLogger

func SetUpLogger(server *gin.Engine)

func SetupContextForSelectedChannel

func SetupContextForSelectedChannel(c *gin.Context, channel *model.Channel, modelName string)

func TokenAuth

func TokenAuth() func(c *gin.Context)

func TokenModelMapping

func TokenModelMapping() func(c *gin.Context)

TokenModelMapping 根据 token 的 ModelMapping 配置,把 ctxkey.RequestModel 映射为目标模型名 只修改 ctxkey.RequestModel,不修改原始请求体 token 的 ModelMapping 字符串由 TokenAuth 中间件预先解析并放入 context 后续的 Distribute 中间件会基于映射后的 RequestModel 选择渠道 后续渠道级的模型映射依然按原有逻辑执行

func TurnstileCheck

func TurnstileCheck() gin.HandlerFunc

func UploadRateLimit

func UploadRateLimit() func(c *gin.Context)

func UserAuth

func UserAuth() func(c *gin.Context)

Types

type AffinityManager

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

func NewAffinityManager

func NewAffinityManager(seconds int) *AffinityManager

func (*AffinityManager) Get

func (am *AffinityManager) Get(userId int, model string) (channelId int, ok bool)

func (*AffinityManager) Remove

func (am *AffinityManager) Remove(userId int, model string)

func (*AffinityManager) Set

func (am *AffinityManager) Set(userId int, model string, channelId int)

type CooldownManager

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

func NewCooldownManager

func NewCooldownManager(seconds int, thresholdSource func() int, windowSource func() int) *CooldownManager

NewCooldownManager 构造冷却管理器。 thresholdSource/windowSource 为 nil 时 resolveThreshold/resolveWindow 返回 0: ReportFailure 中 threshold > 0 条件恒为 false,因此只累计权重、永不触发冷却(仅计数不冷却)。 (注:Go 不支持重载,旧版本曾规划的单参签名 NewCooldownManager(seconds) 不存在。)

func (*CooldownManager) IsCoolingDown

func (cm *CooldownManager) IsCoolingDown(channelId int, model string) bool

func (*CooldownManager) Put

func (cm *CooldownManager) Put(channelId int, model string)

Put 强制立即写入冷却到期时间(兼容语义,供手动/测试场景使用,不计入累计)

func (*CooldownManager) ReportFailure added in v1.0.1

func (cm *CooldownManager) ReportFailure(channelId int, model string, weight int)

ReportFailure 上报一次失败;weight<=0 直接忽略;累计权重达到阈值才写入冷却到期时间, 触发后 failCount 清零(防止冷却解除后立即再次触发需重新累计)。

func (*CooldownManager) ResetChannel added in v1.0.1

func (cm *CooldownManager) ResetChannel(channelId int)

ResetChannel 清除该渠道下所有模型的冷却条目(供手动重置渠道使用)

func (*CooldownManager) ResetSuccess added in v1.0.1

func (cm *CooldownManager) ResetSuccess(channelId int, model string)

ResetSuccess 成功时清零该 key 的失败计数;已冷却中的维持原状(成功不提前解除冷却)。

type ModelRequest

type ModelRequest struct {
	Model string `json:"model" form:"model"`
}

Jump to

Keyboard shortcuts

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