summaryrefslogtreecommitdiff
path: root/typeconv.go
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2017-06-04 16:04:36 -0400
committerDave Henderson <dhenderson@gmail.com>2017-06-05 10:20:44 -0400
commitb1730c1956aed244d9d05255c95f427fdfcf4d1e (patch)
tree19257a9e4ef7fec51177f4a7e36fced7a85055fc /typeconv.go
parenta4ddbc506abd34da600abb392513a1e49ea04548 (diff)
Adding TOML support
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'typeconv.go')
-rw-r--r--typeconv.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/typeconv.go b/typeconv.go
index 2d1734c8..f2597d1a 100644
--- a/typeconv.go
+++ b/typeconv.go
@@ -12,6 +12,8 @@ import (
yaml "gopkg.in/yaml.v2"
+ // XXX: replace once https://github.com/BurntSushi/toml/pull/179 is merged
+ "github.com/hairyhenderson/toml"
"github.com/ugorji/go/codec"
)
@@ -69,6 +71,12 @@ func (t *TypeConv) YAMLArray(in string) []interface{} {
return unmarshalArray(obj, in, yaml.Unmarshal)
}
+// TOML - Unmarshal a TOML Object
+func (t *TypeConv) TOML(in string) interface{} {
+ obj := make(map[string]interface{})
+ return unmarshalObj(obj, in, toml.Unmarshal)
+}
+
func parseCSV(args ...string) (records [][]string, hdr []string) {
delim := ","
var in string
@@ -249,6 +257,16 @@ func (t *TypeConv) ToYAML(in interface{}) string {
return marshalObj(in, yaml.Marshal)
}
+// ToTOML - Stringify a struct as TOML
+func (t *TypeConv) ToTOML(in interface{}) string {
+ buf := new(bytes.Buffer)
+ err := toml.NewEncoder(buf).Encode(in)
+ if err != nil {
+ log.Fatalf("Unable to marshal %s: %v", in, err)
+ }
+ return string(buf.Bytes())
+}
+
// Slice creates a slice from a bunch of arguments
func (t *TypeConv) Slice(args ...interface{}) []interface{} {
return args