Chore: use generics as possible

This commit is contained in:
yaling888
2022-04-24 02:07:57 +08:00
committed by adlyq
parent dee1aeb6c3
commit 4fd7d0f707
29 changed files with 500 additions and 267 deletions

View File

@ -18,7 +18,7 @@ type Fallback struct {
*outbound.Base
disableUDP bool
filter string
single *singledo.Single
single *singledo.Single[[]C.Proxy]
providers []provider.ProxyProvider
failedTimes *atomic.Int32
failedTime *atomic.Int64
@ -115,11 +115,11 @@ func (f *Fallback) Unwrap(metadata *C.Metadata) C.Proxy {
}
func (f *Fallback) proxies(touch bool) []C.Proxy {
elm, _, _ := f.single.Do(func() (any, error) {
elm, _, _ := f.single.Do(func() ([]C.Proxy, error) {
return getProvidersProxies(f.providers, touch, f.filter), nil
})
return elm.([]C.Proxy)
return elm
}
func (f *Fallback) findAliveProxy(touch bool) C.Proxy {
@ -141,7 +141,7 @@ func NewFallback(option *GroupCommonOption, providers []provider.ProxyProvider)
Interface: option.Interface,
RoutingMark: option.RoutingMark,
}),
single: singledo.NewSingle(defaultGetProxiesDuration),
single: singledo.NewSingle[[]C.Proxy](defaultGetProxiesDuration),
providers: providers,
disableUDP: option.DisableUDP,
filter: option.Filter,