github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/common/strmatcher/matchergroup_simple.go (about) 1 package strmatcher 2 3 type matcherEntry struct { 4 matcher Matcher 5 value uint32 6 } 7 8 // SimpleMatcherGroup is an implementation of MatcherGroup. 9 // It simply stores all matchers in an array and sequentially matches them. 10 type SimpleMatcherGroup struct { 11 matchers []matcherEntry 12 } 13 14 // AddMatcher implements MatcherGroupForAll.AddMatcher. 15 func (g *SimpleMatcherGroup) AddMatcher(matcher Matcher, value uint32) { 16 g.matchers = append(g.matchers, matcherEntry{ 17 matcher: matcher, 18 value: value, 19 }) 20 } 21 22 // Match implements MatcherGroup.Match. 23 func (g *SimpleMatcherGroup) Match(input string) []uint32 { 24 result := []uint32{} 25 for _, e := range g.matchers { 26 if e.matcher.Match(input) { 27 result = append(result, e.value) 28 } 29 } 30 return result 31 } 32 33 // MatchAny implements MatcherGroup.MatchAny. 34 func (g *SimpleMatcherGroup) MatchAny(input string) bool { 35 for _, e := range g.matchers { 36 if e.matcher.Match(input) { 37 return true 38 } 39 } 40 return false 41 }