File tree 1 file changed +16
-0
lines changed
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ func funcMap() template.FuncMap {
48
48
// Add some extra functionality
49
49
extra := template.FuncMap {
50
50
"toToml" : toTOML ,
51
+ "fromToml" : fromTOML ,
51
52
"toYaml" : toYAML ,
52
53
"fromYaml" : fromYAML ,
53
54
"fromYamlArray" : fromYAMLArray ,
@@ -132,6 +133,21 @@ func toTOML(v interface{}) string {
132
133
return b .String ()
133
134
}
134
135
136
+ // fromTOML converts a TOML document into a map[string]interface{}.
137
+ //
138
+ // This is not a general-purpose TOML parser, and will not parse all valid
139
+ // TOML documents. Additionally, because its intended use is within templates
140
+ // it tolerates errors. It will insert the returned error message string into
141
+ // m["Error"] in the returned map.
142
+ func fromTOML (str string ) map [string ]interface {} {
143
+ m := make (map [string ]interface {})
144
+
145
+ if err := toml .Unmarshal ([]byte (str ), & m ); err != nil {
146
+ m ["Error" ] = err .Error ()
147
+ }
148
+ return m
149
+ }
150
+
135
151
// toJSON takes an interface, marshals it to json, and returns a string. It will
136
152
// always return a string, even on marshal error (empty string).
137
153
//
You can’t perform that action at this time.
0 commit comments