feat: support merging multiple subscriptions
This commit is contained in:
38
internal/automation/match.go
Normal file
38
internal/automation/match.go
Normal file
@ -0,0 +1,38 @@
|
||||
package automation
|
||||
|
||||
import "strings"
|
||||
|
||||
// matchProxies filters proxies down to those satisfying every non-empty
|
||||
// dimension of m.
|
||||
func matchProxies(proxies []ProxyRef, m MatchRule) []ProxyRef {
|
||||
var out []ProxyRef
|
||||
for _, p := range proxies {
|
||||
if len(m.Subscriptions) > 0 && !containsFold(m.Subscriptions, p.Subscription) {
|
||||
continue
|
||||
}
|
||||
if len(m.NameContains) > 0 && !anyContainsFold(m.NameContains, p.OriginalName) {
|
||||
continue
|
||||
}
|
||||
out = append(out, p)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func containsFold(list []string, s string) bool {
|
||||
for _, item := range list {
|
||||
if strings.EqualFold(item, s) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func anyContainsFold(keywords []string, s string) bool {
|
||||
lower := strings.ToLower(s)
|
||||
for _, kw := range keywords {
|
||||
if strings.Contains(lower, strings.ToLower(kw)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user