454a1be9e1
refactor(app): add test logger helper function
...
Create setupTestLogger() helper to reduce duplicate logger initialization
in test files. Replace 20+ occurrences of logging.NewAppLogger calls.
- Create testutil.go with setupTestLogger() function
- Update app_test.go to use the new helper
- Remove unused logging import from app_test.go
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-08 18:06:55 +08:00
cf2fcca7e8
refactor: 提取公共逻辑、消除重复代码、加强错误处理
...
- 提取 App 公共逻辑到 app_common.go,消除 app.go/app_windows.go 重复定义
- 提取 Server 生命周期/中间件/路由逻辑到独立文件(lifecycle.go/middleware_builder.go/router.go)
- 提取 Proxy 缓存处理/头部修改/目标选择到独立模块
- 提取 CheckIPAccess/CheckTokenAuth 到 utils/httperror.go,消除 status/purge 重复实现
- 修复 stream 双向转发:任一方向完成立即关闭双端,避免连接泄漏
- 修复 SSL/TLS 中静默忽略错误的问题,添加日志记录
- 统一日志消息为英文
💘 Generated with Crush
Assisted-by: GLM 5.1 via Crush <crush@charm.land>
2026-04-28 18:00:48 +08:00
c18ce613b3
style: 格式化代码
...
- 使用 Go 1.13+ 八进制字面量格式 (0o644)
- 修复文件末尾缺少换行符
- 对齐结构体字段
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-27 10:20:18 +08:00
1f672d1a7a
fix(lint): 修复所有 lint 错误
...
- 为导出的函数添加注释 (revive)
- 检查 os.Stdout.Write 返回值 (errcheck)
- 重命名 err 变量避免 shadow declaration (govet)
- 使用 tagged switch 替代 if-else (staticcheck QF1003)
- 用 append 展开替换循环 (staticcheck S1011)
- 添加常量消除重复字符串 (goconst)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-27 10:20:01 +08:00
2122067efb
docs: 更新 AGENTS.md 文档,添加新模块说明
...
- 更新所有 AGENTS.md 时间戳至 2026-04-24
- 添加 converter、e2e、testutil 模块文档
- 更新 README.md:nginx 配置导入、stale 缓存功能说明
- 更新项目统计:132 Go 文件,157 测试文件
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 18:24:31 +08:00
909bd405d2
feat(converter,app): 添加 nginx 配置导入功能
...
- 新增 internal/converter/nginx 解析器和转换器
- main.go 添加 --import/-i 参数支持 nginx 配置导入
- app_test.go 添加导入功能相关测试
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 17:12:49 +08:00
b444f5b1d7
refactor(app): 提取通用函数到 import.go,注释改为英文
...
- 提取 Run、generateConfig、printVersion 到 import.go
- 删除冗长的中文注释,改为简洁英文
- 同步 Windows 版本的结构变化
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 17:12:38 +08:00
6686b8557d
fix(ci): 修复 act 本地运行 CI 测试失败的问题
...
- 修复 captureStdout/captureStderr 管道死锁问题,使用 goroutine 异步读取
- 添加 root 用户跳过权限测试的逻辑(act 容器以 root 运行)
- 更新 golangci-lint 到 v2.11.4 并迁移配置格式
- 更新 golangci-lint-action 到 v7
- 添加 linter continue-on-error 避免阻塞 CI
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-23 19:33:35 +08:00
dafe96b5a3
style(app): 移除测试文件多余空行
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:14:07 +08:00
4d66dd562f
test(app,mimeutil): 添加应用和 MIME 检测测试
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 08:12:34 +08:00
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
e05cf8a674
refactor(version): 模块化版本信息
...
将版本信息从 app.go 移至独立的 version 包,便于多模块引用。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 18:07:21 +08:00
3d80b12f7d
docs: 为其余模块添加标准化 godoc 注释
...
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 11:23:04 +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
5a5f733cb4
refactor(logging): 将日志格式参数从布尔值改为字符串,支持 json/text/console 格式
...
将 Init 接口从 pretty bool 参数改为 format string 参数,
支持 json(纯 JSON)、text(无颜色 ConsoleWriter)、console(带颜色)三种格式。
简化 AppLogger 实现,统一使用 zerolog 格式化输出。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-17 17:26:08 +08:00
359afb5e24
feat(server): 集成 LocationEngine 和 Unix socket 监听支持
...
- 使用 LocationEngine 替代 fasthttp/router 进行路由匹配
- 新增 createListener 支持 Unix domain socket 监听
- 支持热升级场景下的 Unix socket 继承
- 新增 registerProxyRoutesWithLocationEngine 和 registerStaticHandlersWithLocationEngine
- 添加 SetUpgradeManager 方法供 App 层注入
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-17 09:26:38 +08:00
2bc13dd03b
refactor(app): 改用 Servers[0] 替代旧版 Server 配置引用
...
将 cfg.Server 改为 cfg.Servers[0],适配多服务器配置格式。
HTTP/2、HTTP/3 等子模块配置同步更新。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 12:48:48 +08:00
d99011aab6
test(config,app,server): 更新测试适配 servers 配置格式
...
- 所有测试用例使用 Servers[0] 替代 Server
- 断言检查 servers: 替代 server:
- 生成配置测试验证新格式输出
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 10:34:04 +08:00
168d34d58d
refactor(config,app): 默认配置迁移到 servers 格式
...
- DefaultConfig() 使用 Servers[0] 替代 Server
- GenerateConfigYAML() 生成 servers 列表格式
- App.Run() 支持多服务器监听地址日志输出
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-15 10:34:04 +08:00
73ef7f4916
fix(lint): 修复剩余 lint 错误
...
- 统一八进制权限格式为 Go 1.13+ 风格 (0o644/0o755)
- 调整 Target 结构体字段顺序优化内存对齐
- 合并相邻的全局变量声明
- 删除多余空行
- 更新 Makefile 使用 gofumpt 替代 goimports
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:50:14 +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
f31e8afeff
feat(lua): 添加 balancer_by_lua 动态负载均衡功能
...
- 新增 BalancerByLuaConfig 配置,支持 Lua 脚本控制后端选择
- 实现 api_balancer.go Lua API,暴露 set_current_peer 等函数
- Proxy 集成 Lua 引擎,fallback 到标准算法确保可靠性
- 添加负载均衡算法常量提取,消除魔法字符串
- 支持超时控制和备用算法配置
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 16:14:59 +08:00
5bb67f13a0
refactor(app): 使用配置化关闭超时替代硬编码
...
移除硬编码的 shutdownTimeout 变量,改用配置中的 Shutdown.GracefulTimeout
和 Shutdown.FastTimeout:
- handleSignal 从配置读取超时值
- gracefulUpgrade 使用配置的优雅停止超时
- 添加防御性 nil-check 确保配置和服务器实例存在
- Windows 版本同步更新
Windows 和 Unix 平台行为一致化。
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 11:25:47 +08:00
26ffc6b60d
fix(lint): 修复 Windows 平台文件 lint 错误
...
- 调整 App 结构体字段对齐以优化内存布局
- 添加文件末尾换行符
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 09:51:44 +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
e2c9533247
feat(app,server): 添加 Windows 平台兼容性支持
...
- Windows 平台忽略 POSIX 特有信号 (SIGUSR1/2, SIGHUP, SIGQUIT)
- 热升级功能在 Windows 上为空实现 stub
- 分离平台特定代码到独立文件
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 11:46:11 +08:00
ada7357f7d
feat(docker,server): 改进容器信号处理和优雅关闭
...
- 使用 tini 作为 PID 1 init 进程,处理僵尸进程回收和信号转发
- 多次 SIGINT (3次) 支持强制退出
- GoroutinePool.Stop() 添加 5s 超时等待,防止无限阻塞
- GracefulUpgrade 启动 goroutine 等待子进程,避免僵尸进程
- 关闭父进程文件描述符副本,防止泄漏
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 18:30:28 +08:00
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
412bfebdd8
feat(http2): 新增 HTTP/2 支持,集成到服务器和应用
2026-04-09 12:18:52 +08:00
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
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
f698f0af67
test(app): 完善 app 模块测试覆盖率
...
覆盖率从 44.3% 提升至 51.7%,新增测试:
- TestSetupSignalHandlers: 信号处理设置测试
- TestHandleSignal_SIGUSR2: SIGUSR2 热升级信号测试
- TestGracefulUpgrade_NoListener: 无监听器热升级测试
- TestVersionVariables: 版本变量默认值测试
- TestAppFields: App 结构体字段初始化测试
- TestShutdownHTTP3_WithServer: HTTP3 关闭测试
- TestReopenLogs_WithNilConfig: nil 配置重开日志测试
- TestReloadConfig_WithValidConfig: 多次重载配置测试
- TestHandleSignal_AllSignals: 所有信号类型综合测试
注:Run 方法涉及服务器启动循环,适合集成测试而非单元测试
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 18:30:41 +08:00
fc71cf4835
refactor(test): 统一测试文件错误处理风格
...
使用空白标识符忽略测试辅助函数中 Close、ReadFrom、Set 等返回值,
与主代码风格保持一致。
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 17:37:05 +08:00
0f7c69e59b
refactor(app,logging,proxy,ssl): 改进错误处理,使用空白标识符忽略明确不关心的返回值
...
- 使用 _ 忽略 Close、Write、Signal 等函数的错误返回值
- 这些场景的错误处理没有实际意义(关闭时已处于清理阶段)
- 移除 health.go 中未使用的 mu 字段
- proxy 模块使用 for-range 替代 VisitAll 遍历头部
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 17:36:47 +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
a1aa05406c
refactor(app): 集成 AppLogger 统一管理启动/停止/信号日志
...
- 使用 AppLogger 替代 fmt.Print/Fprintf 输出启动停止消息
- 支持 text/json 双格式输出,json 格式输出结构化日志
- 信号处理、配置重载、热升级等流程统一使用 AppLogger
- 重载配置时重建 AppLogger 以应用新格式配置
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 15:02:34 +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
c70ab305b7
test(app,proxy,ssl,stream): 完善测试覆盖率
...
- app: 添加 NewApp/SetPidFile/SetLogFile/sigName 测试
- proxy: 扩展健康检查器测试
- ssl: 添加 TLS 配置和 Close 方法测试
- stream: 添加负载均衡器和 UDP 会话测试
覆盖率从 55.4% 提升至 60.3%
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 13:36:43 +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
aa64329ba2
feat(server,handler,proxy,app): 集成未使用的中间件和模块
...
- 集成 6 个安全/功能中间件到 server.go
- 集成 GoroutinePool 和 SendFile 零拷贝
- 集成 FileCache 和 ProxyCache 缓存模块
- 集成 Stream TCP/UDP 代理模块
- 添加 Stream 配置结构到 config.go
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 11:27:53 +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
179aacac04
docs: 添加模块上下文文档 (AGENTS.md)
...
为各模块添加上下文文档,帮助 AI 助手理解代码结构:
- AGENTS.md: 项目根目录上下文
- docs/AGENTS.md: 文档目录说明
- internal/AGENTS.md: 内部包结构概览
- 各子模块 AGENTS.md: 模块特定上下文和约定
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 16:25:51 +08:00
b445bca96a
feat(server): 实现基础 HTTP 服务器核心功能
...
使用 fasthttp 替代 net/http,实现 Phase 2 核心模块:
- HTTP 服务器:fasthttp.Server 配置超时和连接限制
- 路由系统:fasthttp/router 基于 radix tree 匹配
- 静态文件服务:安全检查、索引文件支持
- 日志系统:zerolog 结构化日志
- 中间件框架:链式组合接口
- 虚拟主机管理:按 Host 头选择处理器
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-02 15:23:54 +08:00
06e8d55ef5
test(config): 添加配置模块单元测试
...
- 添加 internal/app 包测试(版本显示、配置生成)
- 添加 internal/config 包测试(加载、保存、验证、默认值)
- 更新 docs/plan.md 日志系统设计(选用 zerolog)
- 更新 .gitignore 添加 coverage.html
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-02 14:40:56 +08:00
f3e5aad21e
feat(app): 添加信号处理和完善配置结构
...
- 添加 SIGTERM/SIGINT/SIGQUIT 信号处理和优雅停止逻辑
- 完善安全配置:访问控制、速率限制、认证参数
- 完善性能配置:Goroutine 池、连接限制
- 改进配置生成 YAML 格式和注释说明
- 添加编译产物 lolly 到 gitignore
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-02 14:30:24 +08:00
77b0eccf4c
refactor(app): 将应用逻辑抽取到 internal/app 包
...
将版本信息和核心运行逻辑从 main.go 移至 internal/app/app.go,
main.go 仅保留 CLI 参数解析和入口调用。
Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-02 14:12:06 +08:00