Turns out there was an easier way to read the env file.

This commit is contained in:
John Barton (joho) 2013-08-02 13:40:38 +10:00
parent 5896be1361
commit d00d0f7ef4

View File

@ -16,9 +16,8 @@ and all the env vars declared in .env will be avaiable through os.Getenv("SOME_E
package godotenv package godotenv
import ( import (
"bufio"
"errors" "errors"
"io" "io/ioutil"
"os" "os"
"strings" "strings"
) )
@ -49,12 +48,12 @@ func Load(filenames ...string) (err error) {
} }
func loadFile(filename string) (err error) { func loadFile(filename string) (err error) {
file, err := os.Open(filename) content, err := ioutil.ReadFile(filename)
if err != nil { if err != nil {
return return
} }
lines := readRawLines(file) lines := strings.Split(string(content), "\n")
for _, fullLine := range lines { for _, fullLine := range lines {
if !isIgnoredLine(fullLine) { if !isIgnoredLine(fullLine) {
@ -69,25 +68,6 @@ func loadFile(filename string) (err error) {
return return
} }
func readRawLines(file io.Reader) (lines []string) {
lineReader := bufio.NewReader(file)
for line, isPrefix, e := lineReader.ReadLine(); e == nil; line, isPrefix, e = lineReader.ReadLine() {
fullLine := string(line)
if isPrefix {
for {
line, isPrefix, _ = lineReader.ReadLine()
fullLine += string(line)
if !isPrefix {
break
}
}
}
// add a line to the game/parse
lines = append(lines, string(line))
}
return
}
func parseLine(line string) (key string, value string, err error) { func parseLine(line string) (key string, value string, err error) {
if len(line) == 0 { if len(line) == 0 {
err = errors.New("zero length string") err = errors.New("zero length string")