MCPcopy
hub / github.com/spf13/viper / deepSearch

Function deepSearch

util.go:189–211  ·  view source on GitHub ↗

deepSearch scans deep maps, following the key indexes listed in the sequence "path". The last value is expected to be another map, and is returned. In case intermediate keys do not exist, or map to a non-map value, a new map is created and inserted, and the search continues from there: the initial

(m map[string]any, path []string)

Source from the content-addressed store, hash-verified

187// a new map is created and inserted, and the search continues from there:
188// the initial map "m" may be modified!
189func deepSearch(m map[string]any, path []string) map[string]any {
190 for _, k := range path {
191 m2, ok := m[k]
192 if !ok {
193 // intermediate key does not exist
194 // => create it and continue from there
195 m3 := make(map[string]any)
196 m[k] = m3
197 m = m3
198 continue
199 }
200 m3, ok := m2.(map[string]any)
201 if !ok {
202 // intermediate key is a value
203 // => replace with a new map
204 m3 = make(map[string]any)
205 m[k] = m3
206 }
207 // continue search from here
208 m = m3
209 }
210 return m
211}

Callers 3

SetDefaultMethod · 0.85
SetMethod · 0.85
getSettingsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected