|
|
@ -17,6 +17,7 @@ package chartutil
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/base64"
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
"path"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
@ -189,3 +190,31 @@ func FromYaml(str string) map[string]interface{} {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m
|
|
|
|
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).
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// This is designed to be called from a template.
|
|
|
|
|
|
|
|
func ToJson(v interface{}) string {
|
|
|
|
|
|
|
|
data, err := json.Marshal(v)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
// Swallow errors inside of a template.
|
|
|
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(data)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FromJson converts a YAML document into a map[string]interface{}.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// This is not a general-purpose JSON parser, and will not parse all valid
|
|
|
|
|
|
|
|
// YAML 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 FromJson(str string) map[string]interface{} {
|
|
|
|
|
|
|
|
m := map[string]interface{}{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := json.Unmarshal([]byte(str), &m); err != nil {
|
|
|
|
|
|
|
|
m["Error"] = err.Error()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
|
|
|
|
}
|
|
|
|