From b9f270162a3b717e0558d74e5777af0c75f3b5ae Mon Sep 17 00:00:00 2001 From: adlyq <2833154405@qq.com> Date: Thu, 28 Apr 2022 23:06:35 +0800 Subject: [PATCH] refactor: field name --- adapter/outboundgroup/groupbase.go | 15 +++++++-------- adapter/provider/provider.go | 18 +++++++++--------- constant/provider/interface.go | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/adapter/outboundgroup/groupbase.go b/adapter/outboundgroup/groupbase.go index 8fd4c775..7c584239 100644 --- a/adapter/outboundgroup/groupbase.go +++ b/adapter/outboundgroup/groupbase.go @@ -13,7 +13,7 @@ type GroupBase struct { *outbound.Base filter *regexp2.Regexp providers []provider.ProxyProvider - flags map[string]uint + versions map[string]uint proxies map[string][]C.Proxy } @@ -32,7 +32,7 @@ func NewGroupBase(opt GroupBaseOption) *GroupBase { Base: outbound.NewBase(opt.BaseOption), filter: filter, providers: opt.providers, - flags: map[string]uint{}, + versions: map[string]uint{}, proxies: map[string][]C.Proxy{}, } } @@ -52,21 +52,20 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy { } return proxies } - //TODO("Touch Flag 没变的") + //TODO("Touch Version 没变的") for _, pd := range gb.providers { - vt := pd.VehicleType() - if vt == types.Compatible { + if pd.VehicleType() == types.Compatible { if touch { gb.proxies[pd.Name()] = pd.ProxiesWithTouch() } else { gb.proxies[pd.Name()] = pd.Proxies() } - gb.flags[pd.Name()] = pd.Flag() + gb.versions[pd.Name()] = pd.Version() continue } - if flag, ok := gb.flags[pd.Name()]; !ok || flag != pd.Flag() { + if version, ok := gb.versions[pd.Name()]; !ok || version != pd.Version() { var ( proxies []C.Proxy newProxies []C.Proxy @@ -85,7 +84,7 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy { } gb.proxies[pd.Name()] = newProxies - gb.flags[pd.Name()] = pd.Flag() + gb.versions[pd.Name()] = pd.Version() } } var proxies []C.Proxy diff --git a/adapter/provider/provider.go b/adapter/provider/provider.go index be0ce4b1..1a3850a6 100644 --- a/adapter/provider/provider.go +++ b/adapter/provider/provider.go @@ -33,11 +33,11 @@ type proxySetProvider struct { *fetcher proxies []C.Proxy healthCheck *HealthCheck - flag uint + version uint } -func (pp *proxySetProvider) Flag() uint { - return pp.flag +func (pp *proxySetProvider) Version() uint { + return pp.version } func (pp *proxySetProvider) MarshalJSON() ([]byte, error) { @@ -123,10 +123,10 @@ func NewProxySetProvider(name string, interval time.Duration, filter string, veh onUpdate := func(elm any) { ret := elm.([]C.Proxy) pd.setProxies(ret) - if pd.flag == math.MaxUint { - pd.flag = 0 + if pd.version == math.MaxUint { + pd.version = 0 } else { - pd.flag++ + pd.version++ } } @@ -182,11 +182,11 @@ type compatibleProvider struct { name string healthCheck *HealthCheck proxies []C.Proxy - flag uint + version uint } -func (cp *compatibleProvider) Flag() uint { - return cp.flag +func (cp *compatibleProvider) Version() uint { + return cp.version } func (cp *compatibleProvider) MarshalJSON() ([]byte, error) { diff --git a/constant/provider/interface.go b/constant/provider/interface.go index 97c8318a..c00a0ba2 100644 --- a/constant/provider/interface.go +++ b/constant/provider/interface.go @@ -70,7 +70,7 @@ type ProxyProvider interface { // Commonly used in DialContext and DialPacketConn ProxiesWithTouch() []constant.Proxy HealthCheck() - Flag() uint + Version() uint } // Rule Type