From a279d2e0711c3f98894ac3d91c8d5d1f4ea6ddab Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 17 Sep 2019 16:01:22 +0200 Subject: [PATCH] template funcs: got force template funcs to be 'FuncGenerator' --- template/interpolate/funcs.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/template/interpolate/funcs.go b/template/interpolate/funcs.go index 1d76f8f06..94760f516 100644 --- a/template/interpolate/funcs.go +++ b/template/interpolate/funcs.go @@ -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()