xfy 6094327620 docs(matcher): 为 location 匹配引擎添加标准化 godoc 注释
为 matcher 包所有文件添加完整文档注释:
- conflict: 路径冲突检测器
- exact: 精确路径匹配器(O(1) hash map)
- location: 统一匹配引擎(整合所有策略)
- matcher: 匹配结果和接口定义
- named: 命名捕获组匹配器
- prefix: 普通前缀匹配器
- prefix_priority: 前缀优先匹配器(^~)
- radix: Radix Tree 最长前缀匹配
- regex: 正则表达式匹配器

注释说明匹配优先级顺序(精确 > 前缀优先 > 正则 > 普通前缀),
以及各匹配器的使用方法和性能特点。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 10:59:27 +08:00

65 lines
1.6 KiB
Go
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.

// Package matcher 提供 nginx 风格的 location 匹配引擎实现。
//
// 该文件实现命名 location 匹配器,用于内部跳转。
//
// 作者xfy
package matcher
import "github.com/valyala/fasthttp"
// NamedMatcher 命名 location 匹配器。
//
// 对应 nginx 的 @name 语法,用于内部跳转(如 error_page、try_files
// 命名 location 不直接匹配请求路径,而是通过名称引用。
type NamedMatcher struct {
// handler 请求处理器
handler fasthttp.RequestHandler
// name location 名称(不含 @ 前缀)
name string
}
// NewNamedMatcher 创建命名匹配器。
//
// 参数:
// - name: location 名称
// - handler: 关联的请求处理器
//
// 返回值:
// - *NamedMatcher: 命名匹配器实例
func NewNamedMatcher(name string, handler fasthttp.RequestHandler) *NamedMatcher {
return &NamedMatcher{
name: name,
handler: handler,
}
}
// Match 检查路径是否匹配。
//
// 命名 location 不使用路径匹配,始终返回 false。
// 获取命名 location 应使用 LocationEngine.GetNamed()。
func (m *NamedMatcher) Match(_ string) bool {
return false
}
// Result 返回匹配结果。
//
// 返回值:
// - *MatchResult: 包含处理器和命名 location 元数据的结果
func (m *NamedMatcher) Result() *MatchResult {
return &MatchResult{
Handler: m.handler,
Path: "@" + m.name,
Priority: 0,
LocationType: LocationTypeNamed,
}
}
// Name 返回命名 location 的名称。
//
// 返回值:
// - string: location 名称
func (m *NamedMatcher) Name() string {
return m.name
}