| 171 | } |
| 172 | |
| 173 | func valueFromPathAndLeaf(path []interface{}, leaf interface{}) interface{} { |
| 174 | switch component := path[0].(type) { |
| 175 | case int: |
| 176 | if len(path) == 1 { |
| 177 | return []interface{}{ |
| 178 | leaf, |
| 179 | } |
| 180 | } |
| 181 | return []interface{}{ |
| 182 | valueFromPathAndLeaf(path[1:], leaf), |
| 183 | } |
| 184 | default: |
| 185 | if len(path) == 1 { |
| 186 | return TreeBranch{ |
| 187 | TreeItem{ |
| 188 | Key: component, |
| 189 | Value: leaf, |
| 190 | }, |
| 191 | } |
| 192 | } |
| 193 | return TreeBranch{ |
| 194 | TreeItem{ |
| 195 | Key: component, |
| 196 | Value: valueFromPathAndLeaf(path[1:], leaf), |
| 197 | }, |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | func set(branch interface{}, path []interface{}, value interface{}) (interface{}, bool) { |
| 203 | switch branch := branch.(type) { |