1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-24 10:54:43 -05:00

fix: 修复模板中非select、url-test策略组被输出为null的问题

This commit is contained in:
Nite07 2023-09-29 15:58:38 +08:00
parent 773424cdb0
commit 50877b1691
2 changed files with 66 additions and 21 deletions

View File

@ -249,7 +249,7 @@ func MergeSubAndTemplate(temp *model.Subscription, sub *model.Subscription) {
if temp.ProxyGroups[i].IsCountryGrop { if temp.ProxyGroups[i].IsCountryGrop {
continue continue
} }
newProxies := make([]string, 0, len(temp.ProxyGroups[i].Proxies)) newProxies := make([]string, 0)
countryGroupMap := make(map[string]model.ProxyGroup) countryGroupMap := make(map[string]model.ProxyGroup)
for _, v := range sub.ProxyGroups { for _, v := range sub.ProxyGroups {
if v.IsCountryGrop { if v.IsCountryGrop {

View File

@ -15,44 +15,89 @@ type ProxyGroup struct {
Tolerance int `yaml:"tolerance,omitempty"` Tolerance int `yaml:"tolerance,omitempty"`
Lazy bool `yaml:"lazy"` Lazy bool `yaml:"lazy"`
Size int `yaml:"-"` Size int `yaml:"-"`
DisableUDP bool `yaml:"disable-udp,omitempty"`
Strategy string `yaml:"strategy,omitempty"`
} }
type SelectProxyGroup struct { type SelectProxyGroup struct {
Name string `yaml:"name,omitempty"` Name string `yaml:"name,omitempty"`
Type string `yaml:"type,omitempty"` Type string `yaml:"type,omitempty"`
Proxies []string `yaml:"proxies,omitempty"` Proxies []string `yaml:"proxies,omitempty"`
DisableUDP bool `yaml:"disable-udp,omitempty"`
} }
type UrlTestProxyGroup struct { type UrlTestProxyGroup struct {
Name string `yaml:"name,omitempty"` Name string `yaml:"name,omitempty"`
Type string `yaml:"type,omitempty"` Type string `yaml:"type,omitempty"`
Proxies []string `yaml:"proxies,omitempty"` Proxies []string `yaml:"proxies,omitempty"`
Url string `yaml:"url,omitempty"` Url string `yaml:"url,omitempty"`
Interval int `yaml:"interval,omitempty"` Interval int `yaml:"interval,omitempty"`
Tolerance int `yaml:"tolerance,omitempty"` Tolerance int `yaml:"tolerance,omitempty"`
Lazy bool `yaml:"lazy"` Lazy bool `yaml:"lazy"`
DisableUDP bool `yaml:"disable-udp,omitempty"`
}
type LoadBalanceProxyGroup struct {
Name string `yaml:"name,omitempty"`
Type string `yaml:"type,omitempty"`
Proxies []string `yaml:"proxies,omitempty"`
DisableUDP bool `yaml:"disable-udp,omitempty"`
Url string `yaml:"url,omitempty"`
Interval int `yaml:"interval,omitempty"`
Lazy bool `yaml:"lazy"`
Strategy string `yaml:"strategy,omitempty"`
}
type RelayProxyGroup struct {
Name string `yaml:"name,omitempty"`
Type string `yaml:"type,omitempty"`
Proxies []string `yaml:"proxies,omitempty"`
} }
func (p ProxyGroup) MarshalYAML() (interface{}, error) { func (p ProxyGroup) MarshalYAML() (interface{}, error) {
switch p.Type { switch p.Type {
case "select": case "select":
return SelectProxyGroup{ return SelectProxyGroup{
Name: p.Name,
Type: p.Type,
Proxies: p.Proxies,
DisableUDP: p.DisableUDP,
}, nil
case "url-test", "fallback":
return UrlTestProxyGroup{
Name: p.Name,
Type: p.Type,
Proxies: p.Proxies,
Url: p.Url,
Interval: p.Interval,
Tolerance: p.Tolerance,
Lazy: p.Lazy,
DisableUDP: p.DisableUDP,
}, nil
case "load-balance":
return LoadBalanceProxyGroup{
Name: p.Name,
Type: p.Type,
Proxies: p.Proxies,
DisableUDP: p.DisableUDP,
Url: p.Url,
Interval: p.Interval,
Lazy: p.Lazy,
Strategy: p.Strategy,
}, nil
case "relay":
return RelayProxyGroup{
Name: p.Name, Name: p.Name,
Type: p.Type, Type: p.Type,
Proxies: p.Proxies, Proxies: p.Proxies,
}, nil }, nil
case "url-test": default:
return UrlTestProxyGroup{ return SelectProxyGroup{
Name: p.Name, Name: p.Name,
Type: p.Type, Type: p.Type,
Proxies: p.Proxies, Proxies: p.Proxies,
Url: p.Url,
Interval: p.Interval,
Tolerance: p.Tolerance,
Lazy: p.Lazy,
}, nil }, nil
} }
return nil, nil
} }
type ProxyGroupsSortByName []ProxyGroup type ProxyGroupsSortByName []ProxyGroup