|
|
|
|
@ -25,6 +25,7 @@ func init() {
|
|
|
|
|
"cidrhost": interpolationFuncCidrHost(),
|
|
|
|
|
"cidrnetmask": interpolationFuncCidrNetmask(),
|
|
|
|
|
"cidrsubnet": interpolationFuncCidrSubnet(),
|
|
|
|
|
"coalesce": interpolationFuncCoalesce(),
|
|
|
|
|
"compact": interpolationFuncCompact(),
|
|
|
|
|
"concat": interpolationFuncConcat(),
|
|
|
|
|
"element": interpolationFuncElement(),
|
|
|
|
|
@ -145,6 +146,30 @@ func interpolationFuncCidrSubnet() ast.Function {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// interpolationFuncCoalesce implements the "coalesce" function that
|
|
|
|
|
// returns the first non null / empty string from the provided input
|
|
|
|
|
func interpolationFuncCoalesce() ast.Function {
|
|
|
|
|
return ast.Function{
|
|
|
|
|
ArgTypes: []ast.Type{ast.TypeString},
|
|
|
|
|
ReturnType: ast.TypeString,
|
|
|
|
|
Variadic: true,
|
|
|
|
|
VariadicType: ast.TypeString,
|
|
|
|
|
Callback: func(args []interface{}) (interface{}, error) {
|
|
|
|
|
if len(args) < 2 {
|
|
|
|
|
return nil, fmt.Errorf("must provide at least two arguments")
|
|
|
|
|
}
|
|
|
|
|
for _, arg := range args {
|
|
|
|
|
argument := arg.(string)
|
|
|
|
|
|
|
|
|
|
if argument != "" {
|
|
|
|
|
return argument, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "", nil
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// interpolationFuncConcat implements the "concat" function that
|
|
|
|
|
// concatenates multiple strings. This isn't actually necessary anymore
|
|
|
|
|
// since our language supports string concat natively, but for backwards
|
|
|
|
|
|