Documentation
¶
Overview ¶
Package yamlpath was copied, refactored and trimmed from: https://github.com/goccy/go-yaml/blob/4653a1bb5c0047bb37280ac341e2f091cb44352f/path.go
The main difference with the original is that instead of returning a child node value, it returns the node itself. For example:
# Given YAML:
a:
b:
c: 1
# Given path:
a.b
# Original result:
c: 1 node
# New result:
b node
Features which are not used here were removed.
The second major difference is that it attempts to find the closest ast.Node parent if it can't find a direct match. For example:
# Given YAML:
a:
b:
c: 1
# Given path:
a.b.d
# Original result:
error
# New result:
b node
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path represents a single YAMLPath (like).
func FromString ¶
FromString creates a Path from string.
Only a subset of rules are supported in comparison to JSONPath or YAMLPath: $ : the root object/element .<child> : child operator [num] : indexed element of an array
If you want to use reserved characters such as `.` as a key name, enclose them in single quotation as follows ( $.foo.'bar.baz'.name ). If you want to use a single quote with reserved characters, escape it with `\` ( $.foo.'bar.baz\'s value'.name ).
func (*Path) FilterFile ¶
FilterFile filters the whole ast.File.
func (*Path) FilterNode ¶
FilterNode filters single ast.Node. If it cannot find the filtered ast.Node, it will remove the last element from the path and repeat this step until a match is found. In the end, if none of the nodes matched the selector, a root node will be returned.
type PathBuilder ¶
type PathBuilder struct {
// contains filtered or unexported fields
}
PathBuilder represent builder for YAMLPath.
func (*PathBuilder) Build ¶
func (b *PathBuilder) Build() *Path
Build returns the built Path pointer.
func (*PathBuilder) Child ¶
func (b *PathBuilder) Child(name string) *PathBuilder
Child adds '.<name>' to the current path.
func (*PathBuilder) Copy ¶
func (b *PathBuilder) Copy() *PathBuilder
Copy copies the PathBuilder along with its fields.
func (*PathBuilder) Index ¶
func (b *PathBuilder) Index(idx uint) *PathBuilder
Index adds '[<idx>]' to the current path.
func (*PathBuilder) Root ¶
func (b *PathBuilder) Root() *PathBuilder
Root adds '$' to the current path.