You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+18-10
Original file line number
Diff line number
Diff line change
@@ -116,20 +116,28 @@ Existing envs take precendence of envs that are loaded later.
116
116
117
117
The [convention](https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use)
118
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:
119
+
is to create an env named `APP_ENV` and load envs in this order:
120
120
121
121
```go
122
-
env:= os.Getenv("FOO_ENV")
123
-
if"" == env {
124
-
env = "development"
122
+
env:= os.Getenv("APP_ENV")
123
+
ifenv == "" {
124
+
env = "development"
125
125
}
126
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
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
133
141
```
134
142
135
143
If you need to, you can also use `godotenv.Overload()` to defy this convention
0 commit comments