c157be1ce5
refactor(cache): remove unused disk/tiered cache and add helper functions
...
Remove unused disk cache, tiered cache, purge, and config loader code.
Add HashPathWithMethod and MatchPattern helpers for future cache purge API.
Update test to use new mock backend API with ResponseBody field.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-09 17:26:19 +08:00
3b2360162c
refactor(utils): add unified ETag generation function
...
Extract duplicate generateETag function from handler/static.go and
cache/file_cache.go into internal/utils/etag.go. Both functions were
identical, using strconv.AppendInt for zero-allocation ETag generation.
- Create utils.GenerateETag(modTime, size) as the unified implementation
- Update handler/static.go to call utils.GenerateETag
- Update cache/file_cache.go to call utils.GenerateETag
- Remove unused strconv import from static.go
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-08 18:06:13 +08:00
3c96f12f74
feat(cache): store ContentType in FileEntry for cache hits
...
- Add ContentType field to FileEntry struct
- Update Set method signature to accept contentType parameter
- Use cached ContentType in static.go cache hit branches
- Update all test files to use new Set signature
This avoids redundant MIME type detection on cache hits,
reducing lock contention in mimeutil.DetectContentType.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 16:13:42 +08:00
8cc3fdef6f
perf(handler): optimize static file serving performance
...
- Add pathPrefixLen for zero-allocation path stripping
- Precompute ETag in FileCache.Set, reuse on cache hits
- Add MIME LRU cache with O(1) operations using container/list
- Remove sharded cache (eager LRU was slower than single-lock)
- Add FileInfo cache to reduce os.Stat calls (TTL-only strategy)
- Adjust test expectations for normalized root path format
Benchmark results: Lookup 12.7µs → 10.6µs (16% improvement)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 14:17:56 +08:00
b1e1547e36
fix(lint): resolve errcheck and goconst issues
...
- Add nolint comments for sync.Pool.Get() type assertions (pool always returns valid pointers)
- Extract TLS version strings to constants in sslutil/tlsconfig.go
- Extract expires directive strings to constants in handler/static.go
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-30 13:41:15 +08:00
58ed02ceac
perf(cache): FileEntry 池化减少 GC 压力
...
- 添加 entryPool sync.Pool 复用 FileEntry 结构体
- Set 新建路径使用 pool.Get() 获取条目
- removeEntry 重置条目后 pool.Put() 回池
- 添加 BenchmarkFileCacheSet_Pooled 对比测试
Benchmark 结果: steady-state 4 allocs/op
(entry 复用生效,time.Now/list.Element/map 分配不可避免)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-29 09:39:18 +08:00
308529d568
perf(cache): Get 方法读锁优先,double-check 升级写锁
...
将 FileCache.Get 的全局写锁改为读锁优先,仅在需要修改状态
(过期删除、CachedAt 迁移)时升级为写锁并 double-check,
减少读路径的锁竞争。近似 LRU 场景下 Get 不再更新访问时间。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 13:13:18 +08:00
8deda73b24
feat(cache): 添加 stale_if_error 和 stale_if_timeout 缓存接口和实现
...
在 CacheBackend 接口新增 GetStale 方法,支持上游错误时按错误类型
(超时 vs 其他错误)检查对应的 stale 窗口返回过期缓存。
ProxyCache、DiskCache、TieredCache 均实现该方法。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 10:05:39 +08:00
aae378433e
feat(cache): 实现分层缓存架构
...
- 添加 CacheBackend 接口统一内存/磁盘缓存访问
- 实现 DiskCache 磁盘缓存后端,支持目录层级和原子写入
- 实现 TieredCache 分层缓存(L1 内存 + L2 磁盘)
- 修改 ProxyCache.Delete 返回 error 以符合接口
- 添加 CacheStats() 方法实现接口
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 13:15:02 +08:00
d933c1bd98
refactor(cache): 提取 MatchRule 辅助函数并扩展测试
...
将 MatchRule 拆分为 matchPath/matchMethod/matchStatus 三个辅助函数,
提升代码可读性和可测试性。新增测试覆盖:
- AcquireLockWithTimeout 锁超时机制
- RefreshTTL TTL 刷新功能
- SetValidationHeaders 验证头设置
- MatchRule 路径匹配变体(前缀/通配符/精确)
- min_uses 计数阈值
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 08:08:37 +08:00
0a7f7170d5
feat(cache,proxy): 增强代理缓存功能
...
- 添加 min_uses 阈值支持,请求次数达标才缓存
- 添加 cache_lock_timeout 配置,防止缓存锁无限等待
- 添加条件请求支持 (If-Modified-Since/If-None-Match),处理 304 响应
- 添加 background_update_disable 配置,允许禁用后台更新
- 添加 cache_ignore_headers 配置,缓存时忽略指定响应头
- 添加 methods 配置,指定可缓存的 HTTP 方法
- 改进路径匹配逻辑,支持精确匹配和通配符匹配
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 18:23:20 +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
bec8932561
feat(server): 添加缓存清理 API 支持
...
新增 PurgeHandler 处理器,支持:
- 按精确路径和通配符模式清理缓存
- HTTP 方法过滤(默认 GET)
- IP 白名单访问控制(CIDR/单 IP/localhost)
- Token 认证保护
- 三种启动模式路由注册
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-16 16:47:10 +08:00
fa55bfd497
feat(cache): 添加缓存 TTL 新鲜度验证优化
...
在 FileEntry 中新增 CachedAt 字段记录缓存时间,实现 TTL 窗口内的缓存新鲜度验证:
- TTL 内跳过 ModTime 验证,减少 os.Stat 调用
- TTL 过期后验证 ModTime,文件未修改时刷新 CachedAt
- 默认 TTL 设置为 5 秒
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 17:53:51 +08:00
9f04b92a75
perf(cache): 优化 FileCache.Get() 锁粒度
...
移除 defer c.mu.Unlock(),在每个 early return 路径添加显式解锁,
在操作完成后立即释放锁,减少锁持有时间,提高并发性能。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-14 14:12:52 +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
95b6119e34
refactor: 使用标准库 slices/maps 替代自定义函数
...
- 使用 slices.Contains 替代 contains/containsInt 函数
- 使用 maps.Copy 替代手动遍历复制
- 删除 internal/cache 中不再需要的辅助函数
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 13:15:13 +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
931144dd08
refactor(cache): 统一路径匹配函数并增强通配符支持
...
- 删除 file_cache.go 中的 pathMatch() 函数
- 导出 purge.go 中的 MatchPattern() 函数
- 增强 MatchPattern() 支持中间通配符(如 /api/*/users)
- 使用 netutil.ExtractClientIPNet() 替代内联 IP 提取逻辑
- 适配 status 模块使用新的工具函数
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 11:20:19 +08:00
214ea4e9a6
perf(cache,proxy): 使用 uint64 哈希键优化代理缓存性能
...
- ProxyCache 的 entries 和 pending map 从 string 改为 uint64 键
- 新增 buildCacheKeyHash 使用 FNV-64a 计算哈希(零分配)
- 增加原始键碰撞验证,防止哈希冲突误匹配
- 更新相关测试和基准测试
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 15:03:10 +08:00
f2352ab9cc
docs(config,stream,logging,handler,proxy,cache,server,ssl,middleware): 为核心模块添加详细 GoDoc 文档注释
...
- config: 为 Config 和所有子配置结构添加完整文档,包含使用示例和注意事项
- stream: 为负载均衡器和服务器添加详细的参数、返回值和功能说明
- logging: 为日志格式化和输出函数添加文档,说明支持的变量替换
- handler: 为路由器、静态文件和 sendfile 处理器添加文档
- proxy: 为健康检查器和代理功能添加完整文档
- cache/server/ssl/middleware: 补充相关模块的文档注释
- config.example.yaml: 添加可信代理配置、加密套件示例,更新压缩级别说明
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-07 15:36:09 +08:00
ac9153f09d
fix(proxy,stream,server): Phase 8 问题修复与功能完善
...
- WebSocket 代理集成:handleWebSocket 现调用 ProxyWebSocket 实现
- 删除 UDP Stream 冗余代码:移除 udpListener 类型及相关测试
- 热升级监听器继承:改用 net.Listen + Serve 模式支持监听器传递
- 代码格式修复:注释格式调整、字段对齐、文件末尾换行符
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 14:28:00 +08:00
80936ae66b
feat(server,proxy,ssl,docs): 完成 Phase 7 功能完善
...
主要变更:
- WebSocket 代理支持 (internal/proxy/websocket.go)
- OCSP stapling 实现 (internal/ssl/ocsp.go)
- 监控状态端点 (internal/server/status.go)
- 新增 nginx 模块文档 (19-24)
- UDP 代理超时配置支持
- 多模块代码注释完善和功能增强
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 13:13:12 +08:00
9d24263918
feat(stream,server,handler): 实现 Phase 6 性能优化和热升级
...
新增功能:
- stream 模块: 流式传输支持,优化大文件和实时数据传输
- Goroutine 池: 限制并发数量,减少调度开销
- 优雅升级: 零停机热升级,继承父进程监听器
- sendfile: 零拷贝文件传输,大文件直接从内核传输
重构改进:
- App 结构体封装,支持热升级和信号处理
- 配置结构字段对齐和代码清理
- 完善错误处理和日志记录
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 10:39:22 +08:00
8b2f2521f1
feat(cache): 实现文件缓存模块
...
- 基于内存的缓存存储,支持过期时间
- LRU 淘汰策略,控制最大条目数
- 支持文件元数据缓存(大小、修改时间)
- 线程安全的读写操作
- 完整单元测试覆盖
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 10:11:31 +08:00