github.com/yaling888/clash@v1.53.0/rule/group.go (about) 1 package rules 2 3 import ( 4 "github.com/phuslu/log" 5 6 C "github.com/yaling888/clash/constant" 7 ) 8 9 type Group struct { 10 *Base 11 payload string 12 matcher C.Matcher 13 rules []C.Rule 14 } 15 16 func (g *Group) RuleType() C.RuleType { 17 return C.Group 18 } 19 20 func (g *Group) Match(metadata *C.Metadata) bool { 21 rs, err := g.matcher.Match(metadata) 22 if err != nil { 23 log.Warn().Err(err).Str("name", g.matcher.Name()).Msg("[Matcher] match group failed") 24 return false 25 } 26 return rs 27 } 28 29 func (g *Group) Adapter() string { 30 return "" 31 } 32 33 func (g *Group) Payload() string { 34 return g.payload 35 } 36 37 func (g *Group) ShouldResolveIP() bool { 38 return false 39 } 40 41 func (g *Group) SubRules() []C.Rule { 42 return g.rules 43 } 44 45 func (g *Group) RuleExtra() *C.RuleExtra { 46 return nil 47 } 48 49 func NewGroup(payload string, matcher C.Matcher, rules []C.Rule) *Group { 50 return &Group{ 51 Base: &Base{}, 52 payload: payload, 53 matcher: matcher, 54 rules: rules, 55 } 56 } 57 58 var _ C.Rule = (*Group)(nil)