about summary refs log tree commit diff
path: root/context
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2017-02-08T12·11+0100
committerVincent Ambo <tazjin@gmail.com>2017-02-08T12·13+0100
commitd94a0ffc25f5e6205dd2fa770819c2095160800a (patch)
tree5d7bad5791266b6e6a5747bfa69e703c80734dfd /context
parentc58ce7e2ab76a591774ef2537f46665fd0885b1d (diff)
feat context: Add YAML loading support
Closes #5
Diffstat (limited to 'context')
-rw-r--r--context/context.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/context/context.go b/context/context.go
index 612faa39acab..140f11fce7c6 100644
--- a/context/context.go
+++ b/context/context.go
@@ -2,9 +2,12 @@ package context
 
 import (
 	"encoding/json"
+	"fmt"
 	"io/ioutil"
 	"path"
+	"strings"
 
+	"github.com/ghodss/yaml"
 	"github.com/polydawn/meep"
 )
 
@@ -38,7 +41,17 @@ func LoadContextFromFile(filename string) (*Context, error) {
 
 	var c Context
 
-	err = json.Unmarshal(file, &c)
+	if strings.HasSuffix(filename, "json") {
+		err = json.Unmarshal(file, &c)
+	} else if strings.HasSuffix(filename, "yaml") || strings.HasSuffix(filename, "yml") {
+		err = yaml.Unmarshal(file, &c)
+	} else {
+		return nil, meep.New(
+			&ContextLoadingError{Filename: filename},
+			meep.Cause(fmt.Errorf("File format not supported. Must be JSON or YAML.")),
+		)
+	}
+
 	if err != nil {
 		return nil, meep.New(
 			&ContextLoadingError{Filename: filename},