MCPcopy
hub / github.com/grafana/tempo / mergeMaps

Function mergeMaps

integration/util/harness_config_overlay.go:188–219  ·  view source on GitHub ↗

mergeMaps recursively merges overlay map onto base map Values in overlay take precedence over base values

(base, overlay map[any]any)

Source from the content-addressed store, hash-verified

186// mergeMaps recursively merges overlay map onto base map
187// Values in overlay take precedence over base values
188func mergeMaps(base, overlay map[any]any) map[any]any {
189 result := make(map[any]any)
190
191 // Copy all base values
192 for k, v := range base {
193 result[k] = v
194 }
195
196 // Overlay values, recursively merging nested maps
197 for k, v := range overlay {
198 if v == nil {
199 delete(result, k)
200 continue
201 }
202
203 // If both base and overlay have a map at this key, merge recursively
204 if baseVal, exists := result[k]; exists {
205 baseMap, baseIsMap := toMapAnyAny(baseVal)
206 overlayMap, overlayIsMap := toMapAnyAny(v)
207
208 if baseIsMap && overlayIsMap {
209 result[k] = mergeMaps(baseMap, overlayMap)
210 continue
211 }
212 }
213
214 // Otherwise, overlay value replaces base value
215 result[k] = v
216 }
217
218 return result
219}
220
221// toMapAnyAny converts various map types to map[any]any
222func toMapAnyAny(v any) (map[any]any, bool) {

Callers 2

TestMergeMapsFunction · 0.70
applyConfigOverlayFunction · 0.70

Calls 1

toMapAnyAnyFunction · 0.85

Tested by 1

TestMergeMapsFunction · 0.56