Skip to content

Commit

Permalink
Merge pull request #60 from coolaj86/precedence
Browse files Browse the repository at this point in the history
explicitly state env precedence and convention
joho authored Sep 27, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 23d116a + 3896766 commit c0b86d6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -110,6 +110,31 @@ content := getRemoteFileContent()
myEnv, err := godotenv.Unmarshal(content)
```

### Precendence & Conventions

Existing envs take precendence of envs that are loaded later.

The [convention](https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use)
for managing multiple environments (i.e. development, test, production)
is to create an env named `{YOURAPP}_ENV` and load envs in this order:

```go
env := os.Getenv("FOO_ENV")
if "" == env {
env = "development"
}

godotenv.Load(".env." + env + ".local")
if "test" != env {
godotenv.Load(".env.local")
}
godotenv.Load(".env." + env)
godotenv.Load() // The Original .env
```

If you need to, you can also use `godotenv.Overload()` to defy this convention
and overwrite existing envs instead of only supplanting them. Use with caution.

### Command Mode

Assuming you've installed the command as above and you've got `$GOPATH/bin` in your `$PATH`

0 comments on commit c0b86d6

Please sign in to comment.