sing-box/route/rule_item_clash_mode.go

34 lines
612 B
Go
Raw Permalink Normal View History

2022-09-10 06:09:47 +00:00
package route
import (
"strings"
"github.com/sagernet/sing-box/adapter"
)
var _ RuleItem = (*ClashModeItem)(nil)
type ClashModeItem struct {
router adapter.Router
mode string
}
func NewClashModeItem(router adapter.Router, mode string) *ClashModeItem {
return &ClashModeItem{
router: router,
mode: mode,
2022-09-10 06:09:47 +00:00
}
}
func (r *ClashModeItem) Match(metadata *adapter.InboundContext) bool {
clashServer := r.router.ClashServer()
if clashServer == nil {
return false
}
return strings.EqualFold(clashServer.Mode(), r.mode)
2022-09-10 06:09:47 +00:00
}
func (r *ClashModeItem) String() string {
return "clash_mode=" + r.mode
}