From 4a2748eb3c53d0eec35964f820a4f5122b1bdf8c Mon Sep 17 00:00:00 2001 From: "John Barton (joho)" Date: Tue, 30 Jul 2013 18:34:51 +1000 Subject: [PATCH] Yaml style bro. --- godotenv.go | 10 ++++++++++ godotenv_test.go | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/godotenv.go b/godotenv.go index e58a80f..7b215ea 100644 --- a/godotenv.go +++ b/godotenv.go @@ -60,6 +60,16 @@ func parseLine(line string) (key string, value string, err error) { splitString := strings.Split(line, "=") + if len(splitString) != 2 { + // try yaml mode! + splitString = strings.Split(line, ":") + } + + if len(splitString) != 2 { + err = errors.New("Can't separate key from value") + return + } + key = strings.Trim(splitString[0], " ") value = strings.Trim(splitString[1], " \"'") diff --git a/godotenv_test.go b/godotenv_test.go index 44ffe58..eaf0bf3 100644 --- a/godotenv_test.go +++ b/godotenv_test.go @@ -63,4 +63,8 @@ func TestParsing(t *testing.T) { // parses escaped double quotes parseAndCompare(t, "FOO=escaped\\\"bar\"", "FOO", "escaped\"bar") + + // parses yaml style options + parseAndCompare(t, "OPTION_A: 1", "OPTION_A", "1") + }