MCPcopy Create free account
hub / github.com/cozystack/talm / includeFun

Function includeFun

pkg/engine/helm/engine.go:133–152  ·  view source on GitHub ↗

'include' needs to be defined in the scope of a 'tpl' template as well as regular file-loaded templates.

(tmpl *template.Template, includedNames map[string]int)

Source from the content-addressed store, hash-verified

131// 'include' needs to be defined in the scope of a 'tpl' template as
132// well as regular file-loaded templates.
133func includeFun(tmpl *template.Template, includedNames map[string]int) func(string, any) (string, error) {
134 return func(name string, data any) (string, error) {
135 var buf strings.Builder
136
137 if v, ok := includedNames[name]; ok {
138 if v > recursionMaxNums {
139 return "", errors.Wrapf(errors.New("unable to execute template"), "rendering template has a nested reference name: %s", name)
140 }
141
142 includedNames[name]++
143 } else {
144 includedNames[name] = 1
145 }
146
147 err := tmpl.ExecuteTemplate(&buf, name, data)
148 includedNames[name]--
149
150 return buf.String(), err
151 }
152}
153
154// As does 'tpl', so that nested calls to 'tpl' see the templates
155// defined by their enclosing contexts.

Callers 2

tplFunFunction · 0.85
initFunMapMethod · 0.85

Calls 1

StringMethod · 0.80

Tested by

no test coverage detected