xfy 53eaec57ad feat(matcher): 添加 nginx 风格 location 匹配引擎
实现 nginx 兼容的 location 匹配系统,支持:
- 精确匹配 (=) - Hash Map O(1)
- 前缀优先匹配 (^~) - Radix Tree
- 正则匹配 (~, ~*) - 按配置顺序
- 普通前缀匹配 - Radix Tree 最长匹配
- 命名 location (@name) - 内部重定向

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-17 09:26:22 +08:00

37 lines
743 B
Go

package matcher
import (
"github.com/valyala/fasthttp"
)
// ExactMatcher Hash Map 精确匹配
type ExactMatcher struct {
path string
handler fasthttp.RequestHandler
priority int
}
// NewExactMatcher 创建精确匹配器
func NewExactMatcher(path string, handler fasthttp.RequestHandler, priority int) *ExactMatcher {
return &ExactMatcher{
path: path,
handler: handler,
priority: priority,
}
}
// Match 检查路径是否精确匹配
func (m *ExactMatcher) Match(path string) bool {
return m.path == path
}
// Result 返回匹配结果
func (m *ExactMatcher) Result() *MatchResult {
return &MatchResult{
Handler: m.handler,
Path: m.path,
Priority: m.priority,
LocationType: "exact",
}
}