Map returns a copy of the Options as a map[string]any If the Options has a child, it combines the main and child maps, prepending each key with the options depth (e.g., "0.key" for main options, "1.key" for child options, "2.key" for grandchild options, etc.)
()
| 296 | // prepending each key with the options depth |
| 297 | // (e.g., "0.key" for main options, "1.key" for child options, "2.key" for grandchild options, etc.) |
| 298 | func (o *Options) Map() map[string]any { |
| 299 | if o.child == nil { |
| 300 | return maps.Clone(o.m) |
| 301 | } |
| 302 | |
| 303 | totalEntries := len(o.m) |
| 304 | |
| 305 | for c := range o.Descendants() { |
| 306 | totalEntries += len(c.m) |
| 307 | } |
| 308 | |
| 309 | result := make(map[string]any, totalEntries) |
| 310 | |
| 311 | for k, v := range o.m { |
| 312 | result["0."+k] = v |
| 313 | } |
| 314 | |
| 315 | depth := 1 |
| 316 | for c := range o.Descendants() { |
| 317 | for k, v := range c.m { |
| 318 | result[strconv.Itoa(depth)+"."+k] = v |
| 319 | } |
| 320 | depth++ |
| 321 | } |
| 322 | |
| 323 | return result |
| 324 | } |
| 325 | |
| 326 | // NestedMap returns Options as a nested map[string]any. |
| 327 | // Each key is split by dots (.) and the resulting keys are used to create a nested structure. |