Skip to content

Commit c5f2575

Browse files
Modes in environment variable.
1 parent d6ee687 commit c5f2575

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

README.md

+18-10
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,28 @@ Existing envs take precendence of envs that are loaded later.
116116

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

121121
```go
122-
env := os.Getenv("FOO_ENV")
123-
if "" == env {
124-
env = "development"
122+
env := os.Getenv("APP_ENV")
123+
if env == "" {
124+
env = "development"
125125
}
126126

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
127+
base := ".env" // .env
128+
local := base + ".local" // .env.local
129+
mode := base + "." + env // .env.[mode]
130+
localM := mode + ".local" // .env.[mode].local
131+
132+
godotenv.Load(localM, mode, local, base)
133+
```
134+
135+
Sometimes you might have env variables that should not be committed into the codebase, especially if your project is hosted in a public repository. In this case you must add the following snippet in your `.gitignore` file:
136+
137+
```gitignore
138+
# local env files
139+
.env.local
140+
.env.*.local
133141
```
134142

135143
If you need to, you can also use `godotenv.Overload()` to defy this convention

0 commit comments

Comments
 (0)