Skip to content

Commit

Permalink
feat: add function to read directly from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
luisdavim committed May 22, 2022
1 parent 4434f45 commit 5ca76b7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gotenv.go
Expand Up @@ -116,6 +116,17 @@ func StrictParse(r io.Reader) (Env, error) {
return strictParse(r, false)
}

// Read is a function to parse a file line by line and returns the valid Env key/value pair of valid variables.
// It expands the value of a variable from the environment variable but does not set the value to the environment itself.
// This function is skipping any invalid lines and only processing the valid one.
func Read(filename string) (Env, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
return strictParse(f, false)
}

//Unmarshal reads a string line by line and returns the valid Env key/value pair of valid variables.
// It expands the value of a variable from the environment variable but does not set the value to the environment itself.
// This function is returning an error if there are any invalid lines.
Expand Down

0 comments on commit 5ca76b7

Please sign in to comment.