AddMap adds a new map to the parent node If it already exists, returns the existing map If it doesn't exist, returns the new map
(parent *yaml.Node, name string)
| 263 | // If it already exists, returns the existing map |
| 264 | // If it doesn't exist, returns the new map |
| 265 | func AddMap(parent *yaml.Node, name string) *yaml.Node { |
| 266 | for i := 0; i < len(parent.Content); i++ { |
| 267 | if i%2 != 0 { |
| 268 | continue |
| 269 | } |
| 270 | if parent.Content[i].Value == name { |
| 271 | return parent.Content[i+1] |
| 272 | } |
| 273 | } |
| 274 | parent.Content = append(parent.Content, |
| 275 | &yaml.Node{Kind: yaml.ScalarNode, Value: name}) |
| 276 | m := &yaml.Node{Kind: yaml.MappingNode, Content: make([]*yaml.Node, 0)} |
| 277 | parent.Content = append(parent.Content, m) |
| 278 | return m |
| 279 | } |
| 280 | |
| 281 | // YamlVal converts node.Value to a string, int, or bool based on the Tag |
| 282 | func YamlVal(n *yaml.Node) (any, error) { |
no outgoing calls