searchMapWithPathPrefixes searches for a value for path in sourceMap This function is part of the searchIndexableWithPathPrefixes recurring search and should not be called directly from functions other than searchIndexableWithPathPrefixes.
( sourceMap map[string]any, prefixKey string, pathIndex int, path []string, )
| 580 | // This function is part of the searchIndexableWithPathPrefixes recurring search and |
| 581 | // should not be called directly from functions other than searchIndexableWithPathPrefixes. |
| 582 | func (v *Viper) searchMapWithPathPrefixes( |
| 583 | sourceMap map[string]any, |
| 584 | prefixKey string, |
| 585 | pathIndex int, |
| 586 | path []string, |
| 587 | ) any { |
| 588 | next, ok := sourceMap[prefixKey] |
| 589 | if !ok { |
| 590 | return nil |
| 591 | } |
| 592 | |
| 593 | // Fast path |
| 594 | if pathIndex == len(path) { |
| 595 | return next |
| 596 | } |
| 597 | |
| 598 | // Nested case |
| 599 | switch n := next.(type) { |
| 600 | case map[any]any: |
| 601 | return v.searchIndexableWithPathPrefixes(cast.ToStringMap(n), path[pathIndex:]) |
| 602 | case map[string]any, []any: |
| 603 | return v.searchIndexableWithPathPrefixes(n, path[pathIndex:]) |
| 604 | default: |
| 605 | // got a value but nested key expected, do nothing and look for next prefix |
| 606 | } |
| 607 | |
| 608 | // not found |
| 609 | return nil |
| 610 | } |
| 611 | |
| 612 | // isPathShadowedInDeepMap makes sure the given path is not shadowed somewhere |
| 613 | // on its path in the map. |
no test coverage detected