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)
| 187 | // a new map is created and inserted, and the search continues from there: |
| 188 | // the initial map "m" may be modified! |
| 189 | func 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 | } |
no outgoing calls
no test coverage detected