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

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

39 lines
1.0 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-03 | Updated: 2026-04-03 -->
# rewrite
## Purpose
URL 重写中间件,支持正则表达式匹配和替换,实现 URL 路径转换。
## Key Files
| File | Description |
|------|-------------|
| `rewrite.go` | 重写中间件Rewrite 结构体、Rule 定义、正则匹配替换 |
| `rewrite_test.go` | 重写测试 |
## For AI Agents
### Working In This Directory
- 使用正则表达式匹配 URL 路径
- 支持捕获组替换($1、$2 等)
- 重写后继续处理,不终止请求
- 可配置多条规则,按顺序匹配
### Testing Requirements
- 运行测试:`go test ./internal/middleware/rewrite/...`
- 测试正则匹配、捕获组替换、多规则处理
### Common Patterns
- 规则格式Pattern正则→ Replacement替换字符串
- 重写后更新 ctx.Path(),不影响路由匹配
- 匹配失败时跳过该规则
## Dependencies
### Internal
- `../` - 中间件接口定义
- `../../config/` - 重写规则配置
<!-- MANUAL: -->