template funcs: got force template funcs to be 'FuncGenerator'
This commit is contained in:
parent
8b5910c40a
commit
a279d2e071
|
@ -27,7 +27,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Funcs are the interpolation funcs that are available within interpolations.
|
// Funcs are the interpolation funcs that are available within interpolations.
|
||||||
var FuncGens = map[string]FuncGenerator{
|
var FuncGens = map[string]interface{}{
|
||||||
"build_name": funcGenBuildName,
|
"build_name": funcGenBuildName,
|
||||||
"build_type": funcGenBuildType,
|
"build_type": funcGenBuildType,
|
||||||
"env": funcGenEnv,
|
"env": funcGenEnv,
|
||||||
|
@ -43,8 +43,8 @@ var FuncGens = map[string]FuncGenerator{
|
||||||
"vault": funcGenVault,
|
"vault": funcGenVault,
|
||||||
"sed": funcGenSed,
|
"sed": funcGenSed,
|
||||||
|
|
||||||
"upper": funcGenPrimitive(strings.ToUpper),
|
"upper": strings.ToUpper,
|
||||||
"lower": funcGenPrimitive(strings.ToLower),
|
"lower": strings.ToLower,
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrVariableNotSetString = "Error: variable not set:"
|
var ErrVariableNotSetString = "Error: variable not set:"
|
||||||
|
@ -58,7 +58,12 @@ type FuncGenerator func(*Context) interface{}
|
||||||
func Funcs(ctx *Context) template.FuncMap {
|
func Funcs(ctx *Context) template.FuncMap {
|
||||||
result := make(map[string]interface{})
|
result := make(map[string]interface{})
|
||||||
for k, v := range FuncGens {
|
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 {
|
if ctx != nil {
|
||||||
for k, v := range ctx.Funcs {
|
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{} {
|
func funcGenPwd(ctx *Context) interface{} {
|
||||||
return func() (string, error) {
|
return func() (string, error) {
|
||||||
return os.Getwd()
|
return os.Getwd()
|
||||||
|
|
Loading…
Reference in New Issue