You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
842 B
Go
39 lines
842 B
Go
package router
|
|
|
|
import (
|
|
ctxpkg "github.com/noahlann/nnet/pkg/context"
|
|
)
|
|
|
|
// CustomMatcher 自定义匹配器
|
|
type CustomMatcher struct {
|
|
fn func(input MatchInput, ctx ctxpkg.Context) bool
|
|
priority int
|
|
}
|
|
|
|
// NewCustomMatcher 创建自定义匹配器
|
|
func NewCustomMatcher(fn func(input MatchInput, ctx ctxpkg.Context) bool) *CustomMatcher {
|
|
return &CustomMatcher{
|
|
fn: fn,
|
|
priority: 50, // 自定义匹配器默认优先级较低
|
|
}
|
|
}
|
|
|
|
// WithPriority 设置优先级
|
|
func (m *CustomMatcher) WithPriority(priority int) *CustomMatcher {
|
|
m.priority = priority
|
|
return m
|
|
}
|
|
|
|
// Match 匹配数据
|
|
func (m *CustomMatcher) Match(input MatchInput, ctx ctxpkg.Context) bool {
|
|
if m.fn == nil {
|
|
return false
|
|
}
|
|
return m.fn(input, ctx)
|
|
}
|
|
|
|
// Priority 获取优先级
|
|
func (m *CustomMatcher) Priority() int {
|
|
return m.priority
|
|
}
|