Skip to content

Commit 410d972

Browse files
committed
comment
1 parent 2aa83f6 commit 410d972

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

confmap/merge.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import (
1111
)
1212

1313
func mergeAppend(src, dest map[string]any) error {
14+
// mergeAppend recursively merges the src map into the dest map (left to right),
15+
// modifying and expanding the dest map in the process.
16+
// This function does not overwrite component lists, and ensures that the
17+
// final value is a name-aware copy of lists from src and dest.
18+
1419
// Compile the globs once
1520
patterns := []string{
1621
"service::extensions",
@@ -28,13 +33,13 @@ func mergeAppend(src, dest map[string]any) error {
2833
srcFlat, _ := maps.Flatten(src, []string{}, KeyDelimiter)
2934
destFlat, _ := maps.Flatten(dest, []string{}, KeyDelimiter)
3035

31-
for key, sVal := range srcFlat {
32-
if !isMatch(key, globs) {
36+
for sKey, sVal := range srcFlat {
37+
if !isMatch(sKey, globs) {
3338
continue
3439
}
3540

36-
dVal, exists := destFlat[key]
37-
if !exists {
41+
dVal, dOk := destFlat[sKey]
42+
if !dOk {
3843
continue // Let maps.Merge handle missing keys
3944
}
4045

@@ -43,7 +48,7 @@ func mergeAppend(src, dest map[string]any) error {
4348

4449
// Only merge if the value is a slice or array; let maps.Merge handle other types
4550
if srcVal.Kind() == reflect.Slice || srcVal.Kind() == reflect.Array {
46-
srcFlat[key] = mergeSlice(srcVal, destVal)
51+
srcFlat[sKey] = mergeSlice(srcVal, destVal)
4752
}
4853
}
4954

0 commit comments

Comments
 (0)