Unset removes the leaf at parts from data and reports whether the key existed. Intermediate maps are not pruned.
(data map[string]any, parts []string)
| 96 | // Unset removes the leaf at parts from data and reports whether the key |
| 97 | // existed. Intermediate maps are not pruned. |
| 98 | func Unset(data map[string]any, parts []string) bool { |
| 99 | if len(parts) == 0 { |
| 100 | return false |
| 101 | } |
| 102 | cursor := data |
| 103 | for _, part := range parts[:len(parts)-1] { |
| 104 | next, ok := cursor[part].(map[string]any) |
| 105 | if !ok { |
| 106 | return false |
| 107 | } |
| 108 | cursor = next |
| 109 | } |
| 110 | leaf := parts[len(parts)-1] |
| 111 | if _, ok := cursor[leaf]; !ok { |
| 112 | return false |
| 113 | } |
| 114 | delete(cursor, leaf) |
| 115 | return true |
| 116 | } |
| 117 | |
| 118 | // Flatten returns data as a map of dotted key paths to stringified values, |
| 119 | // prefixed with prefix. Slices are flattened by index. |
no outgoing calls