Convert a node to a YAML string for troubleshooting
(node *yaml.Node)
| 181 | |
| 182 | // Convert a node to a YAML string for troubleshooting |
| 183 | func YamlStr(node *yaml.Node) string { |
| 184 | if node == nil { |
| 185 | return "nil" |
| 186 | } |
| 187 | buf := strings.Builder{} |
| 188 | enc := yaml.NewEncoder(&buf) |
| 189 | enc.SetIndent(2) |
| 190 | err := enc.Encode(node) |
| 191 | if err != nil { |
| 192 | return fmt.Sprintf("%s", err) |
| 193 | } |
| 194 | s := buf.String() |
| 195 | return strings.TrimSpace(s) |
| 196 | } |
| 197 | |
| 198 | // Remove a map key-value pair from node.Content |
| 199 | func RemoveFromMap(node *yaml.Node, name string) error { |