summaryrefslogtreecommitdiff
path: root/data/datasource.go
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2018-08-24 21:12:11 -0400
committerDave Henderson <dhenderson@gmail.com>2018-09-24 23:22:40 -0400
commitcc0dc067c7362adfb1de802c86c3bab1601b5fe0 (patch)
treea59826f272902b2ba138c95e3a1eba6cfad7dda6 /data/datasource.go
parent2eeb9a78c06835db36b2df169e26334cb9d65c86 (diff)
Return error instead of using log.Fatal
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'data/datasource.go')
-rw-r--r--data/datasource.go35
1 files changed, 20 insertions, 15 deletions
diff --git a/data/datasource.go b/data/datasource.go
index 7f42cee9..0e676e5b 100644
--- a/data/datasource.go
+++ b/data/datasource.go
@@ -4,7 +4,6 @@ import (
"fmt"
"io"
"io/ioutil"
- "log"
"mime"
"net/http"
"net/url"
@@ -27,7 +26,7 @@ var stdin io.Reader
func regExtension(ext, typ string) {
err := mime.AddExtensionType(ext, typ)
if err != nil {
- log.Fatal(err)
+ panic(err)
}
}
@@ -293,21 +292,21 @@ func (d *Data) Datasource(alias string, args ...string) (interface{}, error) {
func parseData(mimeType, s string) (out interface{}, err error) {
switch mimeType {
case jsonMimetype:
- out = JSON(s)
+ out, err = JSON(s)
case jsonArrayMimetype:
- out = JSONArray(s)
+ out, err = JSONArray(s)
case yamlMimetype:
- out = YAML(s)
+ out, err = YAML(s)
case csvMimetype:
- out = CSV(s)
+ out, err = CSV(s)
case tomlMimetype:
- out = TOML(s)
+ out, err = TOML(s)
case textMimetype:
out = s
default:
return nil, errors.Errorf("Datasources of type %s not yet supported", mimeType)
}
- return out, nil
+ return out, err
}
// DatasourceReachable - Determines if the named datasource is reachable with
@@ -407,10 +406,13 @@ func readHTTP(source *Source, args ...string) ([]byte, error) {
return body, nil
}
-func readConsul(source *Source, args ...string) ([]byte, error) {
+func readConsul(source *Source, args ...string) (data []byte, err error) {
if source.kv == nil {
- source.kv = libkv.NewConsul(source.URL)
- err := source.kv.Login()
+ source.kv, err = libkv.NewConsul(source.URL)
+ if err != nil {
+ return nil, err
+ }
+ err = source.kv.Login()
if err != nil {
return nil, err
}
@@ -421,7 +423,7 @@ func readConsul(source *Source, args ...string) ([]byte, error) {
p = p + "/" + args[0]
}
- data, err := source.kv.Read(p)
+ data, err = source.kv.Read(p)
if err != nil {
return nil, err
}
@@ -429,9 +431,12 @@ func readConsul(source *Source, args ...string) ([]byte, error) {
return data, nil
}
-func readBoltDB(source *Source, args ...string) ([]byte, error) {
+func readBoltDB(source *Source, args ...string) (data []byte, err error) {
if source.kv == nil {
- source.kv = libkv.NewBoltDB(source.URL)
+ source.kv, err = libkv.NewBoltDB(source.URL)
+ if err != nil {
+ return nil, err
+ }
}
if len(args) != 1 {
@@ -439,7 +444,7 @@ func readBoltDB(source *Source, args ...string) ([]byte, error) {
}
p := args[0]
- data, err := source.kv.Read(p)
+ data, err = source.kv.Read(p)
if err != nil {
return nil, err
}