From b1730c1956aed244d9d05255c95f427fdfcf4d1e Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sun, 4 Jun 2017 16:04:36 -0400 Subject: Adding TOML support Signed-off-by: Dave Henderson --- typeconv.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'typeconv.go') 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 -- cgit v1.2.3