NestedMap returns Options as a nested map[string]any. Each key is split by dots (.) and the resulting keys are used to create a nested structure. If the Options has a child, it puts the main and child maps under "0", "1", "2", etc. keys representing the options depth (e.g., "0" for main options, "1"
()
| 329 | // representing the options depth |
| 330 | // (e.g., "0" for main options, "1" for child options, "2" for grandchild options, etc.) |
| 331 | func (o *Options) NestedMap() map[string]any { |
| 332 | if o.child == nil { |
| 333 | return o.nestedMap() |
| 334 | } |
| 335 | |
| 336 | totalMaps := 1 |
| 337 | for child := o.child; child != nil; child = child.child { |
| 338 | totalMaps++ |
| 339 | } |
| 340 | |
| 341 | result := make(map[string]any, totalMaps) |
| 342 | |
| 343 | result["0"] = o.nestedMap() |
| 344 | |
| 345 | depth := 1 |
| 346 | for c := range o.Descendants() { |
| 347 | result[strconv.Itoa(depth)] = c.nestedMap() |
| 348 | depth++ |
| 349 | } |
| 350 | |
| 351 | return result |
| 352 | } |
| 353 | |
| 354 | // String returns Options as a string representation of the map. |
| 355 | func (o *Options) String() string { |