descendStrMap assigns into a native map[string]interface{} target, following the remaining dotted-key parts with plain Go map operations and decoding the value with decodeAny. It returns the map to store back at this level: a new map when v was nil, otherwise v unchanged, since maps are reference ty
(v reflect.Value, path []pathPart, idx int, value *unstable.Node)
| 1551 | // map when v was nil, otherwise v unchanged, since maps are reference types and |
| 1552 | // are mutated in place. |
| 1553 | func (d *decoder) descendStrMap(v reflect.Value, path []pathPart, idx int, value *unstable.Node) (reflect.Value, error) { |
| 1554 | var m map[string]interface{} |
| 1555 | if v.IsNil() { |
| 1556 | m = make(map[string]interface{}) |
| 1557 | v = reflect.ValueOf(m) |
| 1558 | } else { |
| 1559 | m = v.Interface().(map[string]interface{}) |
| 1560 | } |
| 1561 | |
| 1562 | // Walk intermediate parts, creating or reusing nested generic maps. A |
| 1563 | // non-map value at an intermediate key can only occur in a document the |
| 1564 | // seen-tracker has already rejected; replacing it mirrors the reflect |
| 1565 | // path (elemOrNewMap). |
| 1566 | for ; idx < len(path)-1; idx++ { |
| 1567 | name := d.partString(&path[idx]) |
| 1568 | child, _ := m[name].(map[string]interface{}) |
| 1569 | if child == nil { |
| 1570 | child = make(map[string]interface{}) |
| 1571 | m[name] = child |
| 1572 | } |
| 1573 | m = child |
| 1574 | } |
| 1575 | |
| 1576 | av, err := d.decodeAny(value) |
| 1577 | if err != nil { |
| 1578 | return reflect.Value{}, err |
| 1579 | } |
| 1580 | m[d.partString(&path[idx])] = av |
| 1581 | return v, nil |
| 1582 | } |
| 1583 | |
| 1584 | // keyHighlight returns a highlight for the given key part node, falling back |
| 1585 | // to the start of the document. |
no test coverage detected