[test]Add name filter to proxy group

This commit is contained in:
Clash-Mini
2022-01-05 12:19:49 +08:00
parent a15d2535f1
commit bfb976bbdc
7 changed files with 36 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package outboundgroup
import (
"regexp"
"time"
C "github.com/Dreamacro/clash/constant"
@ -11,7 +12,7 @@ const (
defaultGetProxiesDuration = time.Second * 5
)
func getProvidersProxies(providers []provider.ProxyProvider, touch bool) []C.Proxy {
func getProvidersProxies(providers []provider.ProxyProvider, touch bool, filter string) []C.Proxy {
proxies := []C.Proxy{}
for _, provider := range providers {
if touch {
@ -20,5 +21,19 @@ func getProvidersProxies(providers []provider.ProxyProvider, touch bool) []C.Pro
proxies = append(proxies, provider.Proxies()...)
}
}
var filterReg *regexp.Regexp = nil
matchedProxies := []C.Proxy{}
if len(filter) > 0 {
filterReg = regexp.MustCompile(filter)
for _, p := range proxies {
if filterReg.MatchString(p.Name()) {
matchedProxies = append(matchedProxies, p)
}
}
//if no proxy matched, means bad filter, return all proxies
if len(matchedProxies) > 0 {
proxies = matchedProxies
}
}
return proxies
}