Documentation
¶
Index ¶
- Variables
- func AdminAuth() func(c *gin.Context)
- func CORS() gin.HandlerFunc
- func Cache() func(c *gin.Context)
- func CriticalRateLimit() func(c *gin.Context)
- func DefaultSkipPaths() []string
- func Distribute() func(c *gin.Context)
- func DownloadRateLimit() func(c *gin.Context)
- func GlobalAPIRateLimit() func(c *gin.Context)
- func GlobalWebRateLimit() func(c *gin.Context)
- func GzipDecodeMiddleware() gin.HandlerFunc
- func Language() gin.HandlerFunc
- func RegisterDefaultSkipPath(prefix string)
- func RelayPanicRecover() gin.HandlerFunc
- func RequestId() func(c *gin.Context)
- func RootAuth() func(c *gin.Context)
- func SelectChannel(ctx context.Context, group, requestModel string, lastFailedChannelId int, ...) (*model.Channel, string, error)
- func SetUpLogger(server *gin.Engine)
- func SetupContextForSelectedChannel(c *gin.Context, channel *model.Channel, modelName string)
- func TokenAuth() func(c *gin.Context)
- func TokenModelMapping() func(c *gin.Context)
- func TurnstileCheck() gin.HandlerFunc
- func UploadRateLimit() func(c *gin.Context)
- func UserAuth() func(c *gin.Context)
- type AffinityManager
- type CooldownManager
- func (cm *CooldownManager) IsCoolingDown(channelId int, model string) bool
- func (cm *CooldownManager) Put(channelId int, model string)
- func (cm *CooldownManager) ReportFailure(channelId int, model string, weight int)
- func (cm *CooldownManager) ResetChannel(channelId int)
- func (cm *CooldownManager) ResetSuccess(channelId int, model string)
- type ModelRequest
Constants ¶
This section is empty.
Variables ¶
var AffinityGlobal = NewAffinityManager(config.AffinityExpireSeconds)
var CooldownGlobal = NewCooldownManager( config.ChannelCooldownSeconds, func() int { return config.ChannelCooldownErrorThreshold }, func() int { return config.ChannelCooldownErrorWindowSeconds }, )
CooldownGlobal 全局冷却管理器;阈值/窗口采用"运行时读取 config", 数据库更新 OptionMap 后即可立即生效,不会让配置形同虚设。
Functions ¶
func CORS ¶
func CORS() gin.HandlerFunc
func CriticalRateLimit ¶
func DefaultSkipPaths ¶ added in v1.0.1
func DefaultSkipPaths() []string
DefaultSkipPaths 返回当前默认跳过名单的副本(供诊断与验收测试使用)。
func Distribute ¶
func DownloadRateLimit ¶
func GlobalAPIRateLimit ¶
func GlobalWebRateLimit ¶
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 SelectChannel ¶
func SetUpLogger ¶
func TokenModelMapping ¶
TokenModelMapping 根据 token 的 ModelMapping 配置,把 ctxkey.RequestModel 映射为目标模型名 只修改 ctxkey.RequestModel,不修改原始请求体 token 的 ModelMapping 字符串由 TokenAuth 中间件预先解析并放入 context 后续的 Distribute 中间件会基于映射后的 RequestModel 选择渠道 后续渠道级的模型映射依然按原有逻辑执行
func TurnstileCheck ¶
func TurnstileCheck() gin.HandlerFunc
func UploadRateLimit ¶
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)
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"`
}