Closes #4 Use bufio.Scanner to read newLines

pull/4/head
David Bochenski 2014-06-25 16:26:24 +01:00
parent 3c13a80fe1
commit 9c77c4efaf
1 changed files with 10 additions and 3 deletions

View File

@ -16,8 +16,8 @@ and all the env vars declared in .env will be avaiable through os.Getenv("SOME_E
package godotenv
import (
"bufio"
"errors"
"io/ioutil"
"os"
"strings"
)
@ -87,14 +87,21 @@ func loadFile(filename string) (err error) {
}
func readFile(filename string) (envMap map[string]string, err error) {
content, err := ioutil.ReadFile(filename)
file, err := os.Open(filename)
// content, err := ioutil.ReadFile(filename)
if err != nil {
return
}
defer file.Close()
envMap = make(map[string]string)
lines := strings.Split(string(content), "\n")
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
for _, fullLine := range lines {
if !isIgnoredLine(fullLine) {