Helper Functions
Magus extends the basic golang text/template engine by including sprig. This package provides a set of helper functions that can be used in the YAML manifest. Helper functions are used in the render of paths, templates, and conditions.
Example:
manifest:
- path: "{{ snake .name }}.go"
template: |
package {{ .name }}
func {{ camel .name }}() {
// ...
}
Some functions allow to concatenate manipulation of strings using pipelines (e.g. snake .name | pluralize). Functions allowing pipelines use the pipelined value as its last argument. For example, snake .name | default `foo` is equivalent to default `foo` (snake .name). See more about pipelines in the text/template documentation.
Example:
manifest:
- path: "{{ pluralize .name | snake }}.go"
template: |
package {{ .name }}
func {{ camel .name }}() {
// ...
}
Additional functions
In addition to the functions provided by sprig, the following functions are available:
String functions
The following functions are available to manipulate strings:
snake: converts a string to snake case1constant: converts a string to constant case1pascal: converts a string to pascal case1camel: converts a string to camel case1kebab: converts a string to kebab case1pluralize: converts a string to plural form2singularize: converts a string to singular form2
- Using gostrcase↩
- Using go-pluralize↩