mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
feat(pkg/engine): add TOML parsing functionality
Allows to use `fromToml` in templates similar to `fromJson` or `fromYaml`. Closes #12024 Signed-off-by: Dominik Müller <mail@dominikm.de>
This commit is contained in:
parent
e63083492b
commit
f550eda6e9
1 changed files with 16 additions and 0 deletions
|
|
@ -48,6 +48,7 @@ func funcMap() template.FuncMap {
|
|||
// Add some extra functionality
|
||||
extra := template.FuncMap{
|
||||
"toToml": toTOML,
|
||||
"fromToml": fromTOML,
|
||||
"toYaml": toYAML,
|
||||
"fromYaml": fromYAML,
|
||||
"fromYamlArray": fromYAMLArray,
|
||||
|
|
@ -132,6 +133,21 @@ func toTOML(v interface{}) string {
|
|||
return b.String()
|
||||
}
|
||||
|
||||
// fromTOML converts a TOML document into a map[string]interface{}.
|
||||
//
|
||||
// This is not a general-purpose TOML parser, and will not parse all valid
|
||||
// TOML documents. Additionally, because its intended use is within templates
|
||||
// it tolerates errors. It will insert the returned error message string into
|
||||
// m["Error"] in the returned map.
|
||||
func fromTOML(str string) map[string]interface{} {
|
||||
m := make(map[string]interface{})
|
||||
|
||||
if err := toml.Unmarshal([]byte(str), &m); err != nil {
|
||||
m["Error"] = err.Error()
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// toJSON takes an interface, marshals it to json, and returns a string. It will
|
||||
// always return a string, even on marshal error (empty string).
|
||||
//
|
||||
|
|
|
|||
Loading…
Reference in a new issue