Add function to check is YNode zero

This commit is contained in:
Donny Xia
2020-12-11 14:52:35 -08:00
parent cc43a2d732
commit bae3228557
4 changed files with 30 additions and 1 deletions

View File

@@ -54,6 +54,18 @@ func IsYNodeString(n *yaml.Node) bool {
return n.Kind == yaml.ScalarNode && n.Tag == NodeTagString
}
// IsYNodeZero is true if all the public fields in the Node are empty.
// Which means it's not initialized and should be omitted when marshal.
// The Node itself has a method IsZero but it is not released
// in yaml.v3. https://pkg.go.dev/gopkg.in/yaml.v3#Node.IsZero
func IsYNodeZero(n *yaml.Node) bool {
// TODO: Change this to use IsZero when it's avaialable.
return n != nil && n.Kind == 0 && n.Style == 0 && n.Tag == "" && n.Value == "" &&
n.Anchor == "" && n.Alias == nil && n.Content == nil &&
n.HeadComment == "" && n.LineComment == "" && n.FootComment == "" &&
n.Line == 0 && n.Column == 0
}
// Parser parses values into configuration.
type Parser struct {
Kind string `yaml:"kind,omitempty"`