lolly/internal/handler/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.3 KiB
Raw Blame History

handler

Purpose

HTTP 请求处理器,包含路由管理和静态文件服务功能。

Key Files

File Description
router.go 路由器封装:基于 fasthttp/router支持 GET/POST/PUT/DELETE/HEAD
static.go 静态文件处理器:文件路径安全检查、索引文件支持
sendfile.go Sendfile 支持X-Sendfile 头处理、高效文件传输

For AI Agents

Working In This Directory

  • 使用 fasthttp/router 进行路由匹配,基于 radix tree 高效查找
  • 路径参数语法:{name} 命名参数,{name?} 可选参数,{filepath:*} 捕获所有
  • 静态文件处理器包含目录遍历安全检查(拒绝 ".."
  • 索引文件默认为 index.html、index.htm可配置

Testing Requirements

  • 运行测试:go test ./internal/handler/...
  • 测试路由匹配、路径安全检查、索引文件逻辑

Common Patterns

  • 使用 github.com/valyala/fasthttpRequestCtx 处理请求
  • fasthttp.ServeFile() 用于静态文件响应
  • 路由参数通过 ctx.UserValue("name") 获取

Dependencies

External

  • github.com/fasthttp/router - 路由器
  • github.com/valyala/fasthttp - HTTP 框架