Documentation
¶
Index ¶
- func ExtractPathSegments(path string) []string
- func MatchAll(conditions ...func(*contextx.Context) bool) func(*contextx.Context) bool
- func MatchAny(conditions ...func(*contextx.Context) bool) func(*contextx.Context) bool
- func MatchBool(key string, expected bool) func(*contextx.Context) bool
- func MatchContains(key, substring string) func(*contextx.Context) bool
- func MatchMethod(methods []string, method string) bool
- func MatchMethodIn(methods []string) func(*contextx.Context) bool
- func MatchNot(condition func(*contextx.Context) bool) func(*contextx.Context) bool
- func MatchPathGlob(path, pattern string) bool
- func MatchPathWithMethod(path, method, pathPattern string, allowedMethods []string) bool
- func MatchPattern(key, pattern string) func(*contextx.Context) bool
- func MatchPrefix(key, prefix string) func(*contextx.Context) bool
- func MatchString(key, expected string) func(*contextx.Context) bool
- func MatchStringIn(key string, list []string) func(*contextx.Context) bool
- func MatchStringInCaseInsensitive(key string, list []string) func(*contextx.Context) bool
- func MatchStringNotIn(key string, list []string) func(*contextx.Context) bool
- func MatchSuffix(key, suffix string) func(*contextx.Context) bool
- func MatchWildcard(key, pattern string) func(*contextx.Context) bool
- func NormalizePath(path string) string
- type ChainRule
- func (r *ChainRule[T]) Enabled() bool
- func (r *ChainRule[T]) ID() string
- func (r *ChainRule[T]) Match(ctx *contextx.Context) bool
- func (r *ChainRule[T]) Priority() int
- func (r *ChainRule[T]) Result() T
- func (r *ChainRule[T]) When(condition func(*contextx.Context) bool) *ChainRule[T]
- func (r *ChainRule[T]) WithEnabled(enabled bool) *ChainRule[T]
- func (r *ChainRule[T]) WithID(id string) *ChainRule[T]
- func (r *ChainRule[T]) WithPriority(priority int) *ChainRule[T]
- type MatchMiddleware
- type Matcher
- func (m *Matcher[T]) AddRule(rule Rule[T]) *Matcher[T]
- func (m *Matcher[T]) AddRules(rules ...Rule[T]) *Matcher[T]
- func (m *Matcher[T]) ClearRules() *Matcher[T]
- func (m *Matcher[T]) DisableCache() *Matcher[T]
- func (m *Matcher[T]) EnableCache(ttl time.Duration) *Matcher[T]
- func (m *Matcher[T]) Match(ctx *contextx.Context) (T, bool)
- func (m *Matcher[T]) MatchAll(ctx *contextx.Context) []T
- func (m *Matcher[T]) RemoveRule(id string) *Matcher[T]
- func (m *Matcher[T]) ResetStats()
- func (m *Matcher[T]) Stats() map[string]int64
- func (m *Matcher[T]) Use(middleware MatchMiddleware[T]) *Matcher[T]
- type MatcherStats
- type PathMatcher
- type PathMatcherBuilder
- func (b *PathMatcherBuilder) AddContains(pattern string) *PathMatcherBuilder
- func (b *PathMatcherBuilder) AddExact(pattern string) *PathMatcherBuilder
- func (b *PathMatcherBuilder) AddGlob(pattern string) *PathMatcherBuilder
- func (b *PathMatcherBuilder) AddPrefix(pattern string) *PathMatcherBuilder
- func (b *PathMatcherBuilder) AddRegex(pattern string) *PathMatcherBuilder
- func (b *PathMatcherBuilder) AddSuffix(pattern string) *PathMatcherBuilder
- func (b *PathMatcherBuilder) Build() []*PathMatcher
- func (b *PathMatcherBuilder) MatchAll(path string) bool
- func (b *PathMatcherBuilder) MatchAny(path string) bool
- type PathMatcherType
- type Rule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractPathSegments ¶
ExtractPathSegments 提取路径段 示例: ExtractPathSegments("/api/v1/users") => ["api", "v1", "users"]
func MatchContains ¶
MatchContains 包含匹配
func MatchMethod ¶
MatchMethod 检查 HTTP 方法是否匹配 如果 methods 为空,则匹配所有方法 方法名比较不区分大小写
func MatchMethodIn ¶
MatchMethodIn HTTP方法匹配
func MatchPathGlob ¶
MatchPathGlob Glob 模式匹配路径(支持 * 和 ? 通配符,* 可匹配 /) 示例: MatchPathGlob("/api/v1/resource", "/api/*") => true
func MatchPathWithMethod ¶
MatchPathWithMethod 匹配路径和 HTTP 方法 pathPattern 支持 glob 通配符,allowedMethods 为空时匹配所有方法
func MatchPattern ¶
MatchPattern 路径模式匹配
func MatchPrefix ¶
MatchPrefix 前缀匹配
func MatchString ¶
MatchString 字符串精确匹配
func MatchStringIn ¶
MatchStringIn 字符串在列表中
func MatchStringInCaseInsensitive ¶
MatchStringInCaseInsensitive 字符串在列表中(忽略大小写)
func MatchStringNotIn ¶
MatchStringNotIn 字符串不在列表中
func MatchSuffix ¶
MatchSuffix 后缀匹配
func MatchWildcard ¶
MatchWildcard 通配符匹配
func NormalizePath ¶
NormalizePath 标准化路径(移除重复的斜杠,确保正确的开头和结尾) 示例: NormalizePath("//api///users/") => "/api/users"
Types ¶
type ChainRule ¶
type ChainRule[T any] struct { // contains filtered or unexported fields }
ChainRule 链式规则构建器
func (*ChainRule[T]) WithEnabled ¶
WithEnabled 设置是否启用
func (*ChainRule[T]) WithPriority ¶
WithPriority 设置优先级
type MatchMiddleware ¶
MatchMiddleware 匹配中间件
type Matcher ¶
type Matcher[T any] struct { // contains filtered or unexported fields }
Matcher 规则匹配器(并发安全 - 使用 atomic.Pointer 优化性能)
func (*Matcher[T]) EnableCache ¶
EnableCache 启用缓存
func (*Matcher[T]) RemoveRule ¶
RemoveRule 移除规则
func (*Matcher[T]) Use ¶
func (m *Matcher[T]) Use(middleware MatchMiddleware[T]) *Matcher[T]
Use 添加中间件
type MatcherStats ¶
type MatcherStats struct {
// contains filtered or unexported fields
}
MatcherStats 匹配器统计信息
type PathMatcher ¶
type PathMatcher struct {
// contains filtered or unexported fields
}
PathMatcher 路径匹配器
func NewPathMatcher ¶
func NewPathMatcher(matchType PathMatcherType, pattern string) (*PathMatcher, error)
NewPathMatcher 创建路径匹配器
type PathMatcherBuilder ¶
type PathMatcherBuilder struct {
// contains filtered or unexported fields
}
PathMatcherBuilder 路径匹配器构建器
func NewPathMatcherBuilder ¶
func NewPathMatcherBuilder() *PathMatcherBuilder
NewPathMatcherBuilder 创建路径匹配器构建器
func (*PathMatcherBuilder) AddContains ¶
func (b *PathMatcherBuilder) AddContains(pattern string) *PathMatcherBuilder
AddContains 添加包含匹配
func (*PathMatcherBuilder) AddExact ¶
func (b *PathMatcherBuilder) AddExact(pattern string) *PathMatcherBuilder
AddExact 添加精确匹配
func (*PathMatcherBuilder) AddGlob ¶
func (b *PathMatcherBuilder) AddGlob(pattern string) *PathMatcherBuilder
AddGlob 添加 Glob 匹配
func (*PathMatcherBuilder) AddPrefix ¶
func (b *PathMatcherBuilder) AddPrefix(pattern string) *PathMatcherBuilder
AddPrefix 添加前缀匹配
func (*PathMatcherBuilder) AddRegex ¶
func (b *PathMatcherBuilder) AddRegex(pattern string) *PathMatcherBuilder
AddRegex 添加正则匹配
func (*PathMatcherBuilder) AddSuffix ¶
func (b *PathMatcherBuilder) AddSuffix(pattern string) *PathMatcherBuilder
AddSuffix 添加后缀匹配
func (*PathMatcherBuilder) MatchAll ¶
func (b *PathMatcherBuilder) MatchAll(path string) bool
MatchAll 匹配所有模式
func (*PathMatcherBuilder) MatchAny ¶
func (b *PathMatcherBuilder) MatchAny(path string) bool
MatchAny 匹配任意一个模式
type PathMatcherType ¶
type PathMatcherType int
PathMatcherType 路径匹配器类型
const ( // PathMatchExact 精确匹配 PathMatchExact PathMatcherType = iota // PathMatchPrefix 前缀匹配 PathMatchPrefix // PathMatchSuffix 后缀匹配 PathMatchSuffix // PathMatchGlob Glob 模式匹配 (如 /api/*/users) PathMatchGlob // PathMatchRegex 正则表达式匹配 PathMatchRegex // PathMatchContains 包含匹配 PathMatchContains )