node

package
v1.23.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ref    string = "Ref"
	Sub    string = "Fn::Sub"
	GetAtt string = "Fn::GetAtt"
)

Variables

This section is empty.

Functions

func Add added in v1.7.0

func Add(m *yaml.Node, name string, val string)

Add adds a new scalar property to the map

func AddMap added in v1.7.0

func AddMap(parent *yaml.Node, name string) *yaml.Node

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

func Append added in v1.23.0

func Append(n *yaml.Node, a *yaml.Node)

Append appends to node.Content

func Clone

func Clone(node *yaml.Node) *yaml.Node

Clone returns a copy of the provided node

func DecodeMap added in v1.22.0

func DecodeMap(n *yaml.Node) map[string]any

DecodeMap converts a node to a string map

func Diff added in v1.16.0

func Diff(node1, node2 *yaml.Node) (diffs []string)

Diff returns an array of strings describing differences between two nodes

func EncodeMap added in v1.22.0

func EncodeMap(m any) string

EncodeMap attempts to convert an interface to a yaml node

func MakeGetAtt added in v1.22.0

func MakeGetAtt(v1 string, v2 string) *yaml.Node

func MakeMapping added in v1.22.0

func MakeMapping() *yaml.Node

MakeMapping returns a pointer to a new yaml mapping node

func MakeRef added in v1.22.0

func MakeRef(v string) *yaml.Node

func MakeScalar added in v1.22.0

func MakeScalar(v string) *yaml.Node

func MakeSequence added in v1.22.0

func MakeSequence(ss []string) *yaml.Node

func MergeNodes added in v1.20.0

func MergeNodes(original *yaml.Node, override *yaml.Node) *yaml.Node

MergeNodes merges two mapping nodes, replacing original values found in override. Objects, which are yaml Mapping nodes, are merged together so that identical keys are replaced by what is in original. Lists, which are yaml Sequences, are merged such that if the list contains a Mapping, and that Mapping has any identical keys, they are replaced instead of appended.

func RemoveFromMap added in v1.4.0

func RemoveFromMap(node *yaml.Node, name string) error

Remove a map key-value pair from node.Content

func SequenceToStrings added in v1.22.0

func SequenceToStrings(n *yaml.Node) []string

SequenceToStrings converts a sequence of Scalars to a string slice

func SetMapValue added in v1.4.0

func SetMapValue(parent *yaml.Node, name string, val *yaml.Node)

Add or replace a map value

func SetSequenceValue added in v1.8.0

func SetSequenceValue(parent *yaml.Node, val *yaml.Node, sidx int)

Set the value of a sequence element within the node

func StringsFromNode added in v1.22.0

func StringsFromNode(n *yaml.Node) []string

StringsFromNode returns a string slice based on a scalar with a CSV or a sequence.

func ToJson added in v1.4.0

func ToJson(node *yaml.Node) string

Convert a node to JSON

func ToSJson added in v1.7.0

func ToSJson(node *yaml.Node) string

Convert a node to a shortened JSON for easier debugging

func YamlStr added in v1.22.0

func YamlStr(node *yaml.Node) string

Convert a node to a YAML string for troubleshooting

func YamlVal added in v1.7.0

func YamlVal(n *yaml.Node) (any, error)

YamlVal converts node.Value to a string, int, or bool based on the Tag

Types

type NodePair added in v1.4.0

type NodePair struct {
	Key   *yaml.Node
	Value *yaml.Node

	// Parent is used by modules to reference the parent template resource
	Parent *NodePair
}

NodePair represents a !!map key-value pair

func GetParent added in v1.4.0

func GetParent(node *yaml.Node, rootNode *yaml.Node, priorNode *yaml.Node) NodePair

Returns the parent node of node, paired with its name if it's a map pair. If it is not a map pair, only NodePair.Value is not nil. (YAML maps are arrays with even indexes being names and odd indexes being values)

node

Content
  0: Name
  1: Map
    Content
      0: a
      1: b

In the above, if I want b's parent node pair, I get [Name, Map] This allows us to ask "what is the parent's name", which is useful for knowing the logical name of the resource a node belongs to.

For sequence elements that are maps, the Key will be nil

func (*NodePair) String added in v1.8.0

func (np *NodePair) String() string

type SNode added in v1.7.0

type SNode struct {
	Kind    string
	Value   string
	Anchor  string   `json:",omitempty"`
	Content []*SNode `json:",omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL