lolly/internal/server/AGENTS.md
xfy 95030cd68a docs: 更新 AGENTS.md 文档
添加各模块的 AGENTS.md 文档文件,记录模块职责和代码结构

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-03 14:07:42 +08:00

1.6 KiB
Raw Blame History

server

Purpose

HTTP 服务器核心,提供服务器创建、启动、停止和虚拟主机管理功能。

Key Files

File Description
server.go 服务器核心Server 结构体、Start()、Stop()、GracefulStop()
vhost.go 虚拟主机管理VHostManager、VirtualHost、按 Host 头匹配
pool.go 连接池管理Worker 池、连接复用、并发控制
upgrade.go 热升级UpgradeManager、USR2 信号处理、平滑交接
status.go 状态监控健康端点、统计信息、Prometheus 格式

For AI Agents

Working In This Directory

  • 使用 fasthttp.Server 配置超时和连接限制
  • Start() 初始化日志、创建路由、注册静态处理器、应用中间件
  • 默认超时ReadTimeout 30s、WriteTimeout 30s、IdleTimeout 120s
  • Stop() 快速停止,GracefulStop() 等待请求完成
  • VHostManager 支持多虚拟主机,按 Host 头匹配,有默认 fallback

Testing Requirements

  • 运行测试:go test ./internal/server/...
  • 测试服务器启动/停止、虚拟主机匹配

Common Patterns

  • 服务器配置从 config.Config 读取
  • 路由使用 handler.NewRouter() 创建
  • 中间件通过 middleware.NewChain().Apply() 应用
  • Host 头匹配时去除端口号

Dependencies

Internal

  • ../config/ - 服务器配置
  • ../handler/ - 路由和静态处理器
  • ../logging/ - 日志初始化
  • ../middleware/ - 中间件链

External

  • github.com/valyala/fasthttp - HTTP 服务器框架