Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit c0b86d6

Browse files
authored
Merge pull request joho#60 from coolaj86/precedence
explicitly state env precedence and convention
2 parents 23d116a + 3896766 commit c0b86d6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,31 @@ content := getRemoteFileContent()
110110
myEnv, err := godotenv.Unmarshal(content)
111111
```
112112

113+
### Precendence & Conventions
114+
115+
Existing envs take precendence of envs that are loaded later.
116+
117+
The [convention](https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use)
118+
for managing multiple environments (i.e. development, test, production)
119+
is to create an env named `{YOURAPP}_ENV` and load envs in this order:
120+
121+
```go
122+
env := os.Getenv("FOO_ENV")
123+
if "" == env {
124+
env = "development"
125+
}
126+
127+
godotenv.Load(".env." + env + ".local")
128+
if "test" != env {
129+
godotenv.Load(".env.local")
130+
}
131+
godotenv.Load(".env." + env)
132+
godotenv.Load() // The Original .env
133+
```
134+
135+
If you need to, you can also use `godotenv.Overload()` to defy this convention
136+
and overwrite existing envs instead of only supplanting them. Use with caution.
137+
113138
### Command Mode
114139

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

0 commit comments

Comments
 (0)