Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindNodeByContent ¶
FindNodeByContent returns a node whose content is the given content string. This could be a descendent of the given node. If there are multiple such nodes, this will return one of them, but it's unspecified which.
func NewSet ¶
func NewSet[T comparable](ss ...T) map[T]struct{}
func SafeYamlPath ¶
YamlPath returns a subset of the given yaml file, as specified by its path. It uses yamlpath under the hood. See the yamlpath's github page for details, though the package's godocs are easier to read.
tldr: `$.path.to.your[0].subdocument` (the `$` is literally a dollar sign you should use to anchor the path).
This function expects there to be a single node result. If you want a list, select the list's parent instead.
If there are any errors along the way, this will return `// ERROR: ${msg}`.
func UnIndent ¶
UnIndent removes a level of indentation from the given string. The rules are very simple:
- first, drop any leading newlines from the string
- then, find the indentation in the first line, which is defined by the leading tabs-or-spaces in that line
- then, trim that prefix from all lines
The prefix must match exactly, and this method removes it just by invoke strings.CutPrefix -- nothing fancier. In particular, this means that if you're mixing tabs and spaces, you may find yourself in for a bad time: if the first string uses "<space><tab>" and the second uses "<tab><space>", the second does not count as an indentation, and won't be affected.
You can use this to embed yaml within test code as literal strings:
...
SomeField: MyStruct {
foo: unIndent(`
hello: world
counts:
- 1
- 2
hello: world`
),
...
The resulting string will be:
┌────────────┐ ◁─ no newline │hello: world│ ◁─╮ │counts: │ ◁─┤ │ - 1 │ ◁─┼─ no extra indentation │ - 2 │ ◁─┤ │hello: world│ ◁─╯ └────────────┘
Types ¶
This section is empty.