Skip to content

Commit 443a10d

Browse files
committed
simplified version
1 parent 830adb1 commit 443a10d

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

utils/config/config.go

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"os"
55
"path/filepath"
6+
"strconv"
67
"strings"
78
"sync"
89

@@ -167,41 +168,13 @@ func transformChildrenUnderArray(config *koanf.Koanf, root string, subPath strin
167168
}
168169

169170
for i := range array {
170-
tmp := koanf.New(".")
171-
172-
tmp.Load(confmap.Provider(map[string]any{
173-
"item": array[i],
174-
}, "."), nil)
175-
176-
path := "item." + subPath
177-
178-
exists := tmp.Exists(path)
179-
180-
if !exists {
181-
tmp.Load(confmap.Provider(map[string]any{
182-
"item": map[string]any{
183-
subPath: map[string]any{},
184-
},
185-
}, "."), nil)
186-
}
171+
path := root + "." + strconv.Itoa(i) + "." + subPath
187172

188-
transformChildren(tmp, path, transform)
189-
190-
item := tmp.All()["item"]
191-
192-
itemMap, ok := item.(map[string]any)
193-
194-
if ok {
195-
array[i] = itemMap
196-
} else {
197-
array[i] = map[string]any{}
173+
if config.Exists(path) {
174+
transformChildren(config, path, transform)
198175
}
199176
}
200177

201-
config.Load(confmap.Provider(map[string]any{
202-
root: array,
203-
}, "."), nil)
204-
205178
return nil
206179
}
207180

0 commit comments

Comments
 (0)