dir2config: templates: 'default' fn

This commit is contained in:
Mikaël Cluseau 2024-01-06 18:20:03 +01:00
parent b616b710cb
commit 4f48866daa

View File

@ -234,6 +234,24 @@ func (ctx *renderContext) templateFuncs(ctxMap map[string]interface{}) map[strin
funcs := clusterFuncs(ctx.Cluster) funcs := clusterFuncs(ctx.Cluster)
for k, v := range map[string]interface{}{ for k, v := range map[string]interface{}{
"default": func(value, defaultValue any) any {
switch v := value.(type) {
case string:
if v != "" {
return v
}
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, float32, float64:
if v != 0 {
return v
}
default:
if v != nil {
return v
}
}
return defaultValue
},
"tls_key": func(name string) (string, error) { "tls_key": func(name string) (string, error) {
return getKeyCert(name, "tls_key") return getKeyCert(name, "tls_key")
}, },