Skip to content

Commit ef19866

Browse files
committed
Add newTemplate function
Creates a new text.Template with the nginx-proxy FuncMap configured
1 parent 455d5c1 commit ef19866

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

template.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,8 @@ func trimSuffix(suffix, s string) string {
283283
return strings.TrimSuffix(s, suffix)
284284
}
285285

286-
func generateFile(config Config, containers Context) bool {
287-
templatePath := config.Template
288-
tmpl, err := template.New(filepath.Base(templatePath)).Funcs(template.FuncMap{
286+
func newTemplate(name string) *template.Template {
287+
tmpl := template.New(name).Funcs(template.FuncMap{
289288
"closest": arrayClosest,
290289
"coalesce": coalesce,
291290
"contains": contains,
@@ -312,7 +311,13 @@ func generateFile(config Config, containers Context) bool {
312311
"whereNotExist": whereNotExist,
313312
"whereAny": whereAny,
314313
"whereAll": whereAll,
315-
}).ParseFiles(templatePath)
314+
})
315+
return tmpl
316+
}
317+
318+
func generateFile(config Config, containers Context) bool {
319+
templatePath := config.Template
320+
tmpl, err := newTemplate(filepath.Base(templatePath)).ParseFiles(templatePath)
316321
if err != nil {
317322
log.Fatalf("unable to parse template: %s", err)
318323
}

0 commit comments

Comments
 (0)