Get walks data using parts and returns the leaf value plus whether it was found. Intermediate non-map values cause a not-found result.
(data map[string]any, parts []string)
| 60 | // Get walks data using parts and returns the leaf value plus whether it was |
| 61 | // found. Intermediate non-map values cause a not-found result. |
| 62 | func Get(data map[string]any, parts []string) (any, bool) { |
| 63 | cursor := any(data) |
| 64 | for _, part := range parts { |
| 65 | m, ok := cursor.(map[string]any) |
| 66 | if !ok { |
| 67 | return nil, false |
| 68 | } |
| 69 | val, ok := m[part] |
| 70 | if !ok { |
| 71 | return nil, false |
| 72 | } |
| 73 | cursor = val |
| 74 | } |
| 75 | return cursor, true |
| 76 | } |
| 77 | |
| 78 | // Set assigns value at parts inside data, creating intermediate maps as |
| 79 | // needed. Existing non-map intermediates are overwritten with a fresh map. |
no outgoing calls