Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
emilingerslev committed Oct 9, 2018
1 parent 0773065 commit 878b86b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/templates/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"text/template"

"github.com/Masterminds/sprig"
yaml "gopkg.in/yaml.v2"
)

type KeyValuePair struct {
Expand Down Expand Up @@ -129,6 +130,38 @@ func TmplIsnt(a interface{}, b interface{}) bool {
return a != b
}

// ToYaml takes an interface, marshals it to yaml, 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.
//
// Borrowed from github.com/helm/helm/pkg/chartutil
func ToYaml(v interface{}) string {
data, err := yaml.Marshal(v)
if err != nil {
// Swallow errors inside of a template.
return ""
}
return string(data)
}

// FromYaml converts a YAML document into a map[string]interface{}.
//
// This is not a general-purpose YAML 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.
//
// Borrowed from github.com/helm/helm/pkg/chartutil
func FromYaml(str string) map[string]interface{} {
m := map[string]interface{}{}

if err := yaml.Unmarshal([]byte(str), &m); err != nil {
m["Error"] = err.Error()
}
return m
}

// TODO: Add description
func getInner(property string, input interface{}) interface{} {
switch t := input.(type) {
Expand Down

0 comments on commit 878b86b

Please sign in to comment.