searchSliceWithPathPrefixes searches for a value for path in sourceSlice This function is part of the searchIndexableWithPathPrefixes recurring search and should not be called directly from functions other than searchIndexableWithPathPrefixes.
( sourceSlice []any, prefixKey string, pathIndex int, path []string, )
| 544 | // This function is part of the searchIndexableWithPathPrefixes recurring search and |
| 545 | // should not be called directly from functions other than searchIndexableWithPathPrefixes. |
| 546 | func (v *Viper) searchSliceWithPathPrefixes( |
| 547 | sourceSlice []any, |
| 548 | prefixKey string, |
| 549 | pathIndex int, |
| 550 | path []string, |
| 551 | ) any { |
| 552 | // if the prefixKey is not a number or it is out of bounds of the slice |
| 553 | index, err := strconv.Atoi(prefixKey) |
| 554 | if err != nil || len(sourceSlice) <= index { |
| 555 | return nil |
| 556 | } |
| 557 | |
| 558 | next := sourceSlice[index] |
| 559 | |
| 560 | // Fast path |
| 561 | if pathIndex == len(path) { |
| 562 | return next |
| 563 | } |
| 564 | |
| 565 | switch n := next.(type) { |
| 566 | case map[any]any: |
| 567 | return v.searchIndexableWithPathPrefixes(cast.ToStringMap(n), path[pathIndex:]) |
| 568 | case map[string]any, []any: |
| 569 | return v.searchIndexableWithPathPrefixes(n, path[pathIndex:]) |
| 570 | default: |
| 571 | // got a value but nested key expected, do nothing and look for next prefix |
| 572 | } |
| 573 | |
| 574 | // not found |
| 575 | return nil |
| 576 | } |
| 577 | |
| 578 | // searchMapWithPathPrefixes searches for a value for path in sourceMap |
| 579 | // |
no test coverage detected