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

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

46 lines
1.5 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-03 -->
# middleware
## Purpose
中间件框架,定义统一的中间件接口和链式组合机制,包含多个具体中间件实现。
## Key Files
| File | Description |
|------|-------------|
| `middleware.go` | 中间件接口和链Middleware 接口、Chain 结构体、Apply 方法 |
## Subdirectories
| Directory | Purpose |
|-----------|---------|
| `accesslog/` | 访问日志中间件(请求记录、响应统计) |
| `compression/` | 响应压缩中间件Gzip、Deflate |
| `rewrite/` | URL 重写中间件(正则替换、路径转换) |
| `security/` | 安全中间件(访问控制、认证、限流、安全头部) |
## For AI Agents
### Working In This Directory
- `Middleware` 接口定义:`Name() string``Process(next) RequestHandler`
- `Chain` 用于组合多个中间件,按注册顺序逆序包装
- `Apply()` 从最后一个中间件开始包装,确保执行顺序正确
- 后续阶段将添加具体中间件实现(安全、压缩、重写等)
### Testing Requirements
- 运行测试:`go test ./internal/middleware/...`
- 测试链式组合和执行顺序
### Common Patterns
- 中间件使用 `fasthttp.RequestHandler` 函数签名
- 包装模式:`func(ctx) { preProcess(); next(ctx); postProcess() }`
- 空 Chain 的 `Apply()` 直接返回原始 handler
## Dependencies
### External
- `github.com/valyala/fasthttp` - HTTP 框架
<!-- MANUAL: -->