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 --- data.go | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'data.go') diff --git a/data.go b/data.go index 483f141b..995eb5bd 100644 --- a/data.go +++ b/data.go @@ -20,24 +20,20 @@ import ( // logFatal is defined so log.Fatal calls can be overridden for testing var logFatalf = log.Fatalf -func init() { - // Add some types we want to be able to handle which can be missing by default - err := mime.AddExtensionType(".json", "application/json") - if err != nil { - log.Fatal(err) - } - err = mime.AddExtensionType(".yml", "application/yaml") - if err != nil { - log.Fatal(err) - } - err = mime.AddExtensionType(".yaml", "application/yaml") - if err != nil { - log.Fatal(err) - } - err = mime.AddExtensionType(".csv", "text/csv") +func regExtension(ext, typ string) { + err := mime.AddExtensionType(ext, typ) if err != nil { log.Fatal(err) } +} + +func init() { + // Add some types we want to be able to handle which can be missing by default + regExtension(".json", "application/json") + regExtension(".yml", "application/yaml") + regExtension(".yaml", "application/yaml") + regExtension(".csv", "text/csv") + regExtension(".toml", "application/toml") sourceReaders = make(map[string]func(*Source, ...string) ([]byte, error)) @@ -184,18 +180,19 @@ func (d *Data) Datasource(alias string, args ...string) interface{} { log.Fatalf("Couldn't read datasource '%s': %s", alias, err) } s := string(b) + ty := &TypeConv{} if source.Type == "application/json" { - ty := &TypeConv{} return ty.JSON(s) } if source.Type == "application/yaml" { - ty := &TypeConv{} return ty.YAML(s) } if source.Type == "text/csv" { - ty := &TypeConv{} return ty.CSV(s) } + if source.Type == "application/toml" { + return ty.TOML(s) + } log.Fatalf("Datasources of type %s not yet supported", source.Type) return nil } -- cgit v1.2.3