about summary refs log tree commit diff
path: root/util/util.go
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-06-09T18·13+0200
committerVincent Ambo <github@tazj.in>2018-06-09T18·21+0200
commit141355f3505237b11480775fb83b5ba1bfcf7806 (patch)
treec737377a501dc6704cf143d853154b25c1a250e8 /util/util.go
parentb33c353233aae4d73b1567aee41fd5d4cad5bf76 (diff)
refactor(util): Use YAML parser for both JSON & YAML files
JSON is a subset of YAML and the previous detection logic is
unnecessary.
Diffstat (limited to 'util/util.go')
-rw-r--r--util/util.go17
1 files changed, 6 insertions, 11 deletions
diff --git a/util/util.go b/util/util.go
index 947ab6e1c5..ee972e2ee4 100644
--- a/util/util.go
+++ b/util/util.go
@@ -10,10 +10,7 @@
 package util
 
 import (
-	"encoding/json"
-	"fmt"
 	"io/ioutil"
-	"strings"
 
 	"github.com/ghodss/yaml"
 )
@@ -44,19 +41,17 @@ func Merge(in1 *map[string]interface{}, in2 *map[string]interface{}) *map[string
 	return &new
 }
 
-// Loads either a YAML or JSON file from the specified path and deserialises it into the provided interface.
-func LoadJsonOrYaml(filename string, addr interface{}) error {
+// Loads either a YAML or JSON file from the specified path and
+// deserialises it into the provided interface.
+func LoadData(filename string, addr interface{}) error {
 	file, err := ioutil.ReadFile(filename)
 	if err != nil {
 		return err
 	}
 
-	if strings.HasSuffix(filename, "json") {
-		err = json.Unmarshal(file, addr)
-	} else if strings.HasSuffix(filename, "yaml") || strings.HasSuffix(filename, "yml") {
-		err = yaml.Unmarshal(file, addr)
-	} else {
-		return fmt.Errorf("File format not supported. Must be JSON or YAML.")
+	err = yaml.Unmarshal(file, addr)
+	if err != nil {
+		return err
 	}
 
 	return nil