实现 nginx 兼容的 location 匹配系统,支持: - 精确匹配 (=) - Hash Map O(1) - 前缀优先匹配 (^~) - Radix Tree - 正则匹配 (~, ~*) - 按配置顺序 - 普通前缀匹配 - Radix Tree 最长匹配 - 命名 location (@name) - 内部重定向 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
21 lines
352 B
Go
21 lines
352 B
Go
package matcher
|
|
|
|
import "github.com/valyala/fasthttp"
|
|
|
|
// MatchResult 匹配结果
|
|
type MatchResult struct {
|
|
Handler fasthttp.RequestHandler
|
|
Path string
|
|
Priority int
|
|
LocationType string
|
|
|
|
// 正则捕获组
|
|
Captures map[string]string
|
|
}
|
|
|
|
// Matcher 接口
|
|
type Matcher interface {
|
|
Match(path string) bool
|
|
Result() *MatchResult
|
|
}
|