explicitly state env precedence and convention

pull/60/head
AJ ONeal 2018-09-24 21:33:41 -06:00
parent 23d116af35
commit 3896766f7d
1 changed files with 25 additions and 0 deletions

View File

@ -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`