From 50877b1691dfb29077902a5383767e412f1361c0 Mon Sep 17 00:00:00 2001 From: nitezs Date: Fri, 29 Sep 2023 15:58:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=B8=AD=E9=9D=9Eselect=E3=80=81url-test=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E7=BB=84=E8=A2=AB=E8=BE=93=E5=87=BA=E4=B8=BAnull=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/default.go | 2 +- model/proxy_group.go | 85 ++++++++++++++++++++++++++++++--------- 2 files changed, 66 insertions(+), 21 deletions(-) diff --git a/api/controller/default.go b/api/controller/default.go index 0f2676f..2503f4c 100644 --- a/api/controller/default.go +++ b/api/controller/default.go @@ -249,7 +249,7 @@ func MergeSubAndTemplate(temp *model.Subscription, sub *model.Subscription) { if temp.ProxyGroups[i].IsCountryGrop { continue } - newProxies := make([]string, 0, len(temp.ProxyGroups[i].Proxies)) + newProxies := make([]string, 0) countryGroupMap := make(map[string]model.ProxyGroup) for _, v := range sub.ProxyGroups { if v.IsCountryGrop { diff --git a/model/proxy_group.go b/model/proxy_group.go index 2bbba1c..71a5e2a 100644 --- a/model/proxy_group.go +++ b/model/proxy_group.go @@ -15,44 +15,89 @@ type ProxyGroup struct { Tolerance int `yaml:"tolerance,omitempty"` Lazy bool `yaml:"lazy"` Size int `yaml:"-"` + DisableUDP bool `yaml:"disable-udp,omitempty"` + Strategy string `yaml:"strategy,omitempty"` } type SelectProxyGroup struct { - Name string `yaml:"name,omitempty"` - Type string `yaml:"type,omitempty"` - Proxies []string `yaml:"proxies,omitempty"` + Name string `yaml:"name,omitempty"` + Type string `yaml:"type,omitempty"` + Proxies []string `yaml:"proxies,omitempty"` + DisableUDP bool `yaml:"disable-udp,omitempty"` } type UrlTestProxyGroup struct { - Name string `yaml:"name,omitempty"` - Type string `yaml:"type,omitempty"` - Proxies []string `yaml:"proxies,omitempty"` - Url string `yaml:"url,omitempty"` - Interval int `yaml:"interval,omitempty"` - Tolerance int `yaml:"tolerance,omitempty"` - Lazy bool `yaml:"lazy"` + Name string `yaml:"name,omitempty"` + Type string `yaml:"type,omitempty"` + Proxies []string `yaml:"proxies,omitempty"` + Url string `yaml:"url,omitempty"` + Interval int `yaml:"interval,omitempty"` + Tolerance int `yaml:"tolerance,omitempty"` + 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) { switch p.Type { case "select": 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, Type: p.Type, Proxies: p.Proxies, }, nil - case "url-test": - return UrlTestProxyGroup{ - Name: p.Name, - Type: p.Type, - Proxies: p.Proxies, - Url: p.Url, - Interval: p.Interval, - Tolerance: p.Tolerance, - Lazy: p.Lazy, + default: + return SelectProxyGroup{ + Name: p.Name, + Type: p.Type, + Proxies: p.Proxies, }, nil } - return nil, nil } type ProxyGroupsSortByName []ProxyGroup