File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ require (
7
7
github.com/Masterminds/sprig/v3 v3.2.3
8
8
github.com/fsouza/go-dockerclient v1.10.2
9
9
github.com/stretchr/testify v1.8.4
10
+ gopkg.in/yaml.v3 v3.0.1
10
11
)
11
12
12
13
require (
@@ -47,5 +48,4 @@ require (
47
48
golang.org/x/sys v0.16.0 // indirect
48
49
golang.org/x/tools v0.6.0 // indirect
49
50
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
50
- gopkg.in/yaml.v3 v3.0.1 // indirect
51
51
)
Original file line number Diff line number Diff line change @@ -75,6 +75,10 @@ func newTemplate(name string) *template.Template {
75
75
"replace" : strings .Replace ,
76
76
"parseBool" : strconv .ParseBool ,
77
77
"parseJson" : unmarshalJson ,
78
+ "fromYaml" : fromYaml ,
79
+ "toYaml" : toYaml ,
80
+ "mustFromYaml" : mustFromYaml ,
81
+ "mustToYaml" : mustToYaml ,
78
82
"queryEscape" : url .QueryEscape ,
79
83
"sha1" : hashSha1 ,
80
84
"split" : strings .Split ,
Original file line number Diff line number Diff line change
1
+ package template
2
+
3
+ import "gopkg.in/yaml.v3"
4
+
5
+ // fromYaml decodes YAML into a structured value, ignoring errors.
6
+ func fromYaml (v string ) interface {} {
7
+ output , _ := mustFromYaml (v )
8
+ return output
9
+ }
10
+
11
+ // mustFromYaml decodes YAML into a structured value, returning errors.
12
+ func mustFromYaml (v string ) (interface {}, error ) {
13
+ var output interface {}
14
+ err := yaml .Unmarshal ([]byte (v ), & output )
15
+ return output , err
16
+ }
17
+
18
+ // toYaml encodes an item into a YAML string
19
+ func toYaml (v interface {}) string {
20
+ output , _ := mustToYaml (v )
21
+ return string (output )
22
+ }
23
+
24
+ // toYaml encodes an item into a YAML string, returning errors
25
+ func mustToYaml (v interface {}) (string , error ) {
26
+ output , err := yaml .Marshal (v )
27
+ if err != nil {
28
+ return "" , err
29
+ }
30
+ return string (output ), nil
31
+ }
You can’t perform that action at this time.
0 commit comments