Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Undent ¶
Undent removes leading indentation/white-space from given string and returns it as a string. Useful for inlining YAML manifests in Go code. Inline YAML manifests in the Go test files makes it easier to read the test case as opposed to reading verbose-y Go structs.
This Undent implementation is a re-write of Jim Myhrberg's https://github.com/jimeh/Undent. I decided to re-write it because I was unable to understand the original implementation, and thus could not fix it.
For code readability purposes, it is possible to start the literal string with "\n", in which case, the first line is ignored. For example, in the following example, name and labels have the same indentation level but aren't aligned due to the leading '`':
Undent(
` name: foo
labels:
foo: bar`)
Instead, you can write a well-aligned text like this:
Undent(`
name: foo
labels:
foo: bar`)
For code readability purposes, it is also possible to not have the correct number of indentations in the last line. For example:
Undent(`
foo
bar
`)
For code readability purposes, you can also omit the indentations for empty lines. For example:
Undent(`
foo <---- 4 spaces
<---- no indentation here
bar <---- 4 spaces
`)
Types ¶
This section is empty.