11e22c80b8
perf: 零分配优化与 Dial timeout 支持
...
- 添加 b2s/s2b 零分配字节-字符串转换工具函数
- WebSocket 数据转发使用 sync.Pool 复用 32KB buffer
- 条件化 Debug 日志避免非 Debug 级别的字符串分配
- 缓存键哈希计算直接写入 []byte 避免 string 转换
- 使用 bytes.EqualFold 替代 strings.ToLower 进行大小写不敏感比较
- generateETag 使用 strconv.AppendInt 避免 fmt.Sprintf
- 支持 Dial timeout 配置,区分 TCP 连接建立和总连接超时
- MaxConnsPerHost 默认值改为 512(fasthttp 推荐)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-28 20:11:20 +08:00
6f6a8f0455
refactor(adapter): 提取 HTTP/2/3 适配器公共逻辑为 CommonAdapter
...
将 http2 和 http3 适配器中重复的 sync.Pool 管理、流式请求体处理、
上下文重置等逻辑提取到 internal/adapter 包,通过 struct embedding 复用。
同时简化 ConnLimiter 直接实现 middleware.Middleware 接口,移除冗余 wrapper。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-28 17:06:41 +08:00
2458ac1ed1
docs: 为其余模块添加标准化 godoc 注释
...
为剩余模块添加完整文档注释:
- app: 应用生命周期管理
- cache: 文件缓存
- config: 配置加载器
- handler: 静态文件处理和错误页面
- http2/http3: HTTP/2 和 HTTP/3 适配器
- loadbalance: 负载均衡算法和均衡器
- middleware: bodylimit、compression、rewrite、security
- mimeutil: MIME 类型检测
- netutil: URL 处理工具
- resolver: DNS 解析器
- server: 服务器升级处理
- ssl: SSL/TLS 和 OCSP
- stream: 流处理
- testutil: 测试工具
- variable: 变量池和 SSL 变量
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 10:59:53 +08:00
9cbc380de5
perf(http3,compression): 对象池化和流式压缩优化
...
http3:
- Adapter 添加 ctxPool 复用 RequestCtx
- resetContext 方法重置状态避免污染
compression:
- 大响应(>64KB)使用 SetBodyStreamWriter 流式压缩
- 消除 compressed buffer 分配,降低内存峰值
- 新增 streamGzip/streamBrotli 流式方法
- 添加流式压缩测试验证功能正确性
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 11:09:26 +08:00
fd4e164ae6
refactor(security): 滑动窗口限流器使用分段锁优化并发性能
...
将单一 counters map + 全局 mutex 改为 16 buckets 分段锁结构:
- 新增 limiterBucket 结构体,每个桶独立持有 RW 锁和计数器 map
- 使用 FNV-1a 哈希算法将键均匀分布到 16 个桶中
- 各方法修改为按 bucket 分发操作:
- Allow() / allowApproximate() / allowPrecise()
- Reset() / ResetAll() / Cleanup()
- GetStats() / GetCount()
收益:
- 并发场景下锁竞争降低约 94% (16 个桶并行)
- 基准测试显示并行 Allow 操作约 89ns/op
测试验证:
- go test -race 通过并发安全测试
- 基准测试显示吞吐提升
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 14:26:01 +08:00
0e3ce8cf52
perf(http3): 移除 ctxPool sync.Pool 提升性能
...
基准测试显示 sync.Pool 反而降低性能:
- 有池:574 ns/op ~ 704 ns/op
- 无池:263 ns/op ~ 264 ns/op
移除池化逻辑,直接创建 RequestCtx 对象。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 14:17:43 +08:00
d21e27fbac
fix(lint): 修复 golangci-lint 错误 (119 -> 0 issues)
...
主要修复:
- errcheck: defer Close 使用 //nolint:errcheck,类型断言改为 ok 检查
- govet fieldalignment: 调整结构体字段顺序优化内存布局
- revive unused-parameter: 将未使用参数改为 _
- exhaustive: 添加缺失的 switch case 或 default
- goconst: 提取重复字符串为常量 (accessAllow, accessDeny 等)
- staticcheck SA9003: 修复空分支逻辑
- gofmt: 运行 gofmt -w 格式化
- nolintlint: 修复 nolint 注释格式
其他改进:
- 更新 .golangci.yml 配置,启用更严格的检查
- 移除未使用的代码和导入
- 简化测试辅助函数调用
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:15:31 +08:00
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
7a98a0b044
refactor: 抽取网络工具函数到 netutil 包,移除冗余代码
...
- 新增 internal/netutil 包,统一 IP 提取和 URL 解析函数
- proxy/websocket/middleware 使用 netutil 替代重复实现
- 移除 handler/sendfile 中未使用的 BufferPool 相关代码
- 移除 http3/adapter 中未使用的反向转换函数
- 提取 server.registerStaticHandler 函数改进代码结构
- 优化 access.go 锁范围,减少持锁时间
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 18:24:21 +08:00
96ed39e162
refactor(http3,handler,server,middleware): 改进错误处理与代码优化
...
- 使用 _ 忽略 Close、Write、Shutdown 等返回值
- compression 使用 switch-case 替代 if-else 链
- http3/adapter 使用 for-range 替代 VisitAll 遍历头部
- sendfile 添加 nolint 注释说明 buffer pool 设计决策
- defer 关闭文件使用 func() { _ = file.Close() } 确保执行
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 17:36:58 +08:00
d42844b2fa
test(app,handler,server,http3): 补充单元测试覆盖率
...
- app: 添加信号处理、配置重载、日志重开测试
- handler/sendfile: 添加小文件、偏移量、错误情况测试
- server: 添加统计追踪、监听器、TLS配置测试
- http3: 新增 adapter 和 server 单元测试
- 格式修复: 末尾换行符、注释对齐
- 文档: AGENTS.md 添加 http3 模块说明
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 16:25:21 +08:00
d6367a1c38
feat(http3,docs,middleware): 实现 Phase 9 HTTP/3 与性能优化扩展
...
- 新增 HTTP/3 (QUIC) 服务器支持,集成到 App 生命周期管理
- 新增 nginx 内置变量速查表文档
- 完善多篇 nginx 文档(代理、安全、流、限流、HTTP/2/3、核心事件)
- 新增一致性哈希负载均衡、gzip_static、滑动窗口限流中间件
- 扩展配置支持 HTTP/3 和日志格式选项
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 15:39:06 +08:00