fix(proxy): filter out empty proxy groups

This commit is contained in:
Chang lue Tsen 2025-04-28 17:30:40 +09:00
parent 3fd71a472b
commit 105ee9cc46
2 changed files with 29 additions and 1 deletions

View File

@ -30,7 +30,7 @@ func NewAdapter(nodes []*server.Server, rules []*server.RuleGroup) *Adapter {
} }
} }
// 合并代理组 // 合并代理组
proxyGroup = append(proxyGroup, g...) proxyGroup = RemoveEmptyGroup(append(proxyGroup, g...))
return &Adapter{ return &Adapter{
Adapter: proxy.Adapter{ Adapter: proxy.Adapter{
Proxies: proxies, Proxies: proxies,

View File

@ -195,3 +195,31 @@ func RemoveEmptyString(arr []string) []string {
} }
return result return result
} }
// RemoveElement 移除指定元素
func RemoveElement(arr []string, element ...string) []string {
var result []string
for _, str := range arr {
if !tool.Contains(element, str) {
logger.Infof("Remove Element: %s", str)
result = append(result, str)
}
}
return result
}
func RemoveEmptyGroup(arr []proxy.Group) []proxy.Group {
var result []proxy.Group
var removeNames []string
for _, group := range arr {
if group.Name == "手动选择" {
group.Proxies = RemoveElement(group.Proxies, removeNames...)
}
if len(group.Proxies) > 0 {
result = append(result, group)
} else {
removeNames = append(removeNames, group.Name)
}
}
return result
}