xfy ca03c121d3 refactor(matcher): 提取 LocationType 常量并优化结构体字段布局
- 添加 LocationType 常量定义替代硬编码字符串
- 优化 MatchResult、ExactMatcher、NamedMatcher 结构体字段顺序
- RadixTree.Insert 添加 locationType 参数用于调试追踪
- 更新测试代码适配新接口

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-17 10:11:45 +08:00

38 lines
808 B
Go

package matcher
import "github.com/valyala/fasthttp"
// NamedMatcher @命名 location
type NamedMatcher struct {
handler fasthttp.RequestHandler
name string
}
// NewNamedMatcher 创建命名匹配器
func NewNamedMatcher(name string, handler fasthttp.RequestHandler) *NamedMatcher {
return &NamedMatcher{
name: name,
handler: handler,
}
}
// Match 检查命名是否匹配(命名 location 不使用 path 匹配)
func (m *NamedMatcher) Match(_ string) bool {
return false
}
// Result 返回匹配结果
func (m *NamedMatcher) Result() *MatchResult {
return &MatchResult{
Handler: m.handler,
Path: "@" + m.name,
Priority: 0,
LocationType: LocationTypeNamed,
}
}
// Name 返回命名 location 的名称
func (m *NamedMatcher) Name() string {
return m.name
}