lolly/internal/server/AGENTS.md
xfy 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

46 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!-- Parent: ../AGENTS.md -->
<!-- Generated: 2026-04-02 | Updated: 2026-04-02 -->
# server
## Purpose
HTTP 服务器核心,提供服务器创建、启动、停止和虚拟主机管理功能。
## Key Files
| File | Description |
|------|-------------|
| `server.go` | 服务器核心Server 结构体、Start()、Stop()、GracefulStop() |
| `vhost.go` | 虚拟主机管理VHostManager、VirtualHost、按 Host 头匹配 |
## 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 服务器框架
<!-- MANUAL: -->