forked from coop-cloud-mirrors/godotenv
Turns out there was an easier way to read the env file.
This commit is contained in:
parent
5896be1361
commit
d00d0f7ef4
26
godotenv.go
26
godotenv.go
@ -16,9 +16,8 @@ and all the env vars declared in .env will be avaiable through os.Getenv("SOME_E
|
||||
package godotenv
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
@ -49,12 +48,12 @@ func Load(filenames ...string) (err error) {
|
||||
}
|
||||
|
||||
func loadFile(filename string) (err error) {
|
||||
file, err := os.Open(filename)
|
||||
content, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
lines := readRawLines(file)
|
||||
lines := strings.Split(string(content), "\n")
|
||||
|
||||
for _, fullLine := range lines {
|
||||
if !isIgnoredLine(fullLine) {
|
||||
@ -69,25 +68,6 @@ func loadFile(filename string) (err error) {
|
||||
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) {
|
||||
if len(line) == 0 {
|
||||
err = errors.New("zero length string")
|
||||
|
Loading…
x
Reference in New Issue
Block a user