github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/swarmkit/template/template.go (about) 1 package template 2 3 import ( 4 "strings" 5 "text/template" 6 ) 7 8 // funcMap defines functions for our template system. 9 var funcMap = template.FuncMap{ 10 "join": func(s ...string) string { 11 // first arg is sep, remaining args are strings to join 12 return strings.Join(s[1:], s[0]) 13 }, 14 } 15 16 func newTemplate(s string, extraFuncs template.FuncMap) (*template.Template, error) { 17 tmpl := template.New("expansion").Option("missingkey=error").Funcs(funcMap) 18 if len(extraFuncs) != 0 { 19 tmpl = tmpl.Funcs(extraFuncs) 20 } 21 return tmpl.Parse(s) 22 }