Skip to content
This repository was archived by the owner on Oct 22, 2026. It is now read-only.

feat(server): make sticky rotation limit configurable - #191

Open
wzwjustdoit wants to merge 2 commits into
rockswang:masterfrom
wzwjustdoit:feat/sticky-max-requests-config
Open

wzwjustdoit wants to merge 2 commits into
rockswang:masterfrom
wzwjustdoit:feat/sticky-max-requests-config

Conversation

@wzwjustdoit

@wzwjustdoit wzwjustdoit commented Oct 22, 2026 •

Copy link
Copy Markdown

让粘性路由轮换阈值可配置

背景

internal/server/handler.go 原先将同渠道粘性账号的轮换阈值硬编码为 50。本 PR 新增 server.sticky_max_requests,允许通过 config.json 调整连续成功使用多少次后轮换账号。

配置

{
  "server": {
    "max_request_body_mb": 128,
    "sticky_max_requests": 50
  }
}
配置状态 生效行为 文件写入
字段缺失 使用默认值 50 加载时不主动写盘;用户下次从面板保存配置时自然写入
正整数 使用配置值 保持不变
0 或负数 记录 warning,内存回退到 50 加载时不主动写盘

非法值不会阻止程序启动,日志格式如下:

<timestamp> WARN config: server.sticky_max_requests=0 invalid, fallback=50

实现

  • internal/config
    • 新增 server.sticky_max_requests 字段。
    • 在默认配置中设为 50。
    • 对非法值执行 warning 与内存回退。
  • cmd/wild-work
    • 启动时将配置值注入 server.Handler。
  • internal/server
    • 新建粘性记录时使用注入值,移除调用处的硬编码 50。
  • config.example.json
    • 补充 server.sticky_max_requests: 50。

cmd/wild-work/main.go 中同组 struct literal 的空白对齐变化由新增字段后的 gofmt 产生,无逻辑变化。

兼容性

  • 旧配置缺少该字段时,行为与升级前一致,默认值仍为 50。
  • 不新增前端设置项,也不增加运行中热更新。
  • 与其他配置文件字段一致,修改后重启生效。

验证

  • go test ./...
  • go vet ./...
  • git diff --check
  • Windows 产物已重建:dist/wild-work.exe

回归覆盖

  • 老配置缺少字段时使用默认值,且加载过程不写盘。
  • 用户保存配置后,默认值被自然写回文件。
  • 显式正整数配置正确生效。
  • 0 与负数触发 warning 并回退到 50,且加载过程不写盘。
  • 真实请求累计到配置阈值后触发粘性轮换,并继续使用同一阈值。
  • 直接构造 Handler 且未传入新字段时,仍兼容回落默认值 50。

提交

  • 83077ed feat(server): make sticky rotation limit configurable
  • 0442ee3 style(config): use structured warning log for sticky limit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant