template funcs: got force template funcs to be 'FuncGenerator'

This commit is contained in:
Adrien Delorme 2019-09-17 16:01:22 +02:00
parent 8b5910c40a
commit a279d2e071
1 changed files with 9 additions and 10 deletions

View File

@ -27,7 +27,7 @@ func init() {
}
// Funcs are the interpolation funcs that are available within interpolations.
var FuncGens = map[string]FuncGenerator{
var FuncGens = map[string]interface{}{
"build_name": funcGenBuildName,
"build_type": funcGenBuildType,
"env": funcGenEnv,
@ -43,8 +43,8 @@ var FuncGens = map[string]FuncGenerator{
"vault": funcGenVault,
"sed": funcGenSed,
"upper": funcGenPrimitive(strings.ToUpper),
"lower": funcGenPrimitive(strings.ToLower),
"upper": strings.ToUpper,
"lower": strings.ToLower,
}
var ErrVariableNotSetString = "Error: variable not set:"
@ -58,7 +58,12 @@ type FuncGenerator func(*Context) interface{}
func Funcs(ctx *Context) template.FuncMap {
result := make(map[string]interface{})
for k, v := range FuncGens {
result[k] = v(ctx)
switch v := v.(type) {
case FuncGenerator:
result[k] = v(ctx)
default:
result[k] = v
}
}
if ctx != nil {
for k, v := range ctx.Funcs {
@ -126,12 +131,6 @@ func funcGenIsotime(ctx *Context) interface{} {
}
}
func funcGenPrimitive(value interface{}) FuncGenerator {
return func(ctx *Context) interface{} {
return value
}
}
func funcGenPwd(ctx *Context) interface{} {
return func() (string, error) {
return os.Getwd()