Add pure template-resolution logic (kctl.ResolveTemplate) with unit tests

This commit is contained in:
Stefan Koelle
2026-08-09 13:49:38 +02:00
parent 79c861682b
commit 1f87cdbf08
2 changed files with 57 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
package kctl
import "strings"
// ResolveTemplate replaces "{key}" placeholders in template with the
// corresponding value from values. Placeholders with no matching key are
// left untouched, so a misconfigured template is visible (e.g. a literal
// "{typo}" in the result) instead of silently collapsing to an empty
// string.
func ResolveTemplate(template string, values map[string]string) string {
result := template
for k, v := range values {
result = strings.ReplaceAll(result, "{"+k+"}", v)
}
return result
}