优化结构

This commit is contained in:
Yvan
2026-08-22 22:34:33 +08:00
parent 0126995090
commit b18baf1547
26 changed files with 501 additions and 80 deletions
+21 -4
View File
@@ -3,6 +3,7 @@
package runtimeconfig
import (
"bytes"
"encoding/json"
"strings"
"sync"
@@ -41,6 +42,13 @@ func cloneConfig(config Config) Config {
return config
}
func sameConfig(left, right Config) bool {
return left.Kind == right.Kind &&
left.Provider == right.Provider &&
left.Enabled == right.Enabled &&
bytes.Equal(left.Values, right.Values)
}
func (s *Store) Get(kind, provider string) (Config, bool) {
if s == nil {
return Config{}, false
@@ -105,11 +113,20 @@ func (s *Store) Replace(configs []Config) {
s.mu.Unlock()
changed := make(map[string]Config, len(previous)+len(next))
for key, config := range previous {
changed[key] = Config{Kind: config.Kind, Provider: config.Provider}
for key, previousConfig := range previous {
nextConfig, exists := next[key]
if !exists {
changed[key] = Config{Kind: previousConfig.Kind, Provider: previousConfig.Provider}
continue
}
if !sameConfig(previousConfig, nextConfig) {
changed[key] = nextConfig
}
}
for key, config := range next {
changed[key] = config
for key, nextConfig := range next {
if _, exists := previous[key]; !exists {
changed[key] = nextConfig
}
}
for _, item := range listeners {
if config, ok := changed[configKey(item.kind, item.provider)]; ok {