13 Commits

Author SHA1 Message Date
xfy
f145a8770e refactor: modernize code with Go 1.22+ features
Apply modern Go patterns across the codebase:
- Replace `interface{}` with `any` (Go 1.18+)
- Use `for range n` instead of `for i := 0; i < n; i++` (Go 1.22+)
- Replace `sort.Slice` with `slices.Sort` from slices package
- Simplify sync.WaitGroup patterns with errgroup where appropriate
- Add Makefile targets for modernize analyzer

Total: 84 files updated, net reduction of 79 lines

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 10:37:45 +08:00
xfy
3c8413b7a6 fix(test): add missing Type field in BenchmarkE2EBasicAuth
The AuthConfig struct requires Type="basic" for NewBasicAuth to
validate successfully. Without this field, the benchmark fails with
"unsupported auth type: ".

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 08:01:43 +08:00
xfy
247fa81c00 fix(lua): 修复 Lua 引擎并发安全问题
- 缓存 coroutine.yield/status 函数,避免并发读取全局 Lua 状态机
- 添加 ngxRegisterMu 锁保护共享 ngx 表的并发写入
- 各 API 注册函数检查字段是否已存在,避免重复写入
- TCPSocket.currentOp 字段添加锁保护

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 14:19:11 +08:00
xfy
abf0315fd8 test(integration): 后端故障切换 E2E 基准测试
测试负载均衡器剔除/恢复后端的开销:
- NormalSelect: 43 allocs/op (正常场景)
- AllUnhealthy: 9 allocs/op (无可用后端)
- SelectOnly: 2 allocs/op (纯选择开销)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 10:47:47 +08:00
xfy
0cf943fede refactor(config,test): 优化 parseSize 为 switch 并适配 NewProxyCache 签名
将 parseSize 的 if-else 改为 switch 语句;更新集成测试中
NewProxyCache 调用以匹配新增的 stale_if_error/stale_if_timeout 参数。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 10:41:56 +08:00
xfy
604bc719f9 test(integration): 添加缓存和代理集成测试
- cache_integration_test.go: 缓存创建、存取、过期、stale、并发测试
- proxy_integration_test.go: 代理创建、负载均衡、超时、健康检查测试

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 14:59:12 +08:00
xfy
ae0bec6c3b feat(internal): 实现 internal 指令
- 新增 IsInternalRedirect 检测内部重定向请求
- static handler 支持 internal 访问限制
- proxy handler 支持 internal 访问限制
- 支持 X-Accel-Redirect 内部重定向

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:09:06 +08:00
xfy
b0ca037cad test(integration): 添加正则 location 配置集成测试
- 测试 ~ 修饰符大小写敏感匹配
- 测试 ~* 修饰符大小写不敏感匹配
- 测试 ^~ 修饰符非正则前缀优先匹配

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 16:04:36 +08:00
xfy
ddc9e0cef1 test(integration): 添加端到端集成性能基准测试
覆盖静态文件、代理转发、中间件链、Lua 脚本和多路由场景的完整请求路径吞吐量。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 11:44:45 +08:00
xfy
8b382606df Merge branch 'lint-fix' - resolve sendfile.go conflict
Conflict: sendfile.go (!linux build tag) was incorrectly modified to
include linuxSendfile and getSocketFd functions which already exist
in sendfile_linux.go.

Resolution: Keep HEAD version (simple fallback returning ENOTSUP) as
Linux implementation is properly separated in sendfile_linux.go.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 09:26:48 +08:00
xfy
4e826925ac refactor: 适配核心模块类型重命名
适配 variable.NewContext/ReleaseContext
适配 resolver.DNSCacheEntry
适配 logging/formatJSON 常量

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 09:41:07 +08:00
xfy
392d0b3449 docs: 新增模块 AGENTS.md 文档,更新目录索引
- 新增 http2、integration、resolver、variable 模块 AGENTS.md
- 更新 internal/AGENTS.md 目录表,补充新模块条目
- 更新 docs/prompts.md 添加 generate-config 缺失项分析提示
- 同步更新日期戳至 2026-04-09

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-09 13:35:29 +08:00
xfy
9495a548e6 feat(proxy,server,logging): 集成变量系统和 DNS 解析器
变量系统集成:
- logging: 访问日志使用 variable 包展开模板
- rewrite: 重写规则支持变量展开
- proxy: 请求/响应头设置支持变量展开

DNS 解析器集成:
- app: 创建并启用 Resolver
- server: SetResolver/GetResolver 方法传递给 proxy
- proxy: SetResolver/Start 方法,后台 DNS 刷新协程
- proxy_dns.go: DNS 刷新逻辑和 IP 直连支持

新增集成测试:
- internal/integration/variable_test.go
- internal/integration/resolver_test.go

文档更新:
- docs/config-reference.md 配置参考文档

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 11:36:49 +08:00