sing-box/route/rule/rule_item_clash_mode.go

33 lines
616 B
Go
Raw Normal View History

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