fix 修复proxies 替换时names没换的bug

This commit is contained in:
timerzz 2024-12-11 11:24:59 +08:00
parent 0f07bb9f10
commit a581c72a65

View File

@ -11,7 +11,7 @@ var ProxiesList = NewProxies(make([]Proxy, 0))
type Proxies struct {
proxies []Proxy
names sync.Map
names *sync.Map
m sync.RWMutex
}
@ -40,6 +40,7 @@ func (p *Proxy) Mapping() map[string]any {
func NewProxies(proxies []Proxy) *Proxies {
return &Proxies{
proxies: proxies,
names: &sync.Map{},
}
}
@ -108,7 +109,13 @@ func (p *Proxies) Mapping() []map[string]any {
// 替换
func (p *Proxies) Replace(proxies []Proxy) {
names := &sync.Map{}
for _, proxy := range proxies {
name := proxy.ClashProxy().Name()
names.Store(name, struct{}{})
}
p.m.Lock()
defer p.m.Unlock()
p.names = names
p.proxies = proxies
}