Skip to content

Commit

Permalink
Modes in environment variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
anteriovieira authored Jul 1, 2020
1 parent d6ee687 commit c5f2575
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,28 @@ 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:
is to create an env named `APP_ENV` and load envs in this order:

```go
env := os.Getenv("FOO_ENV")
if "" == env {
env = "development"
env := os.Getenv("APP_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
base := ".env" // .env
local := base + ".local" // .env.local
mode := base + "." + env // .env.[mode]
localM := mode + ".local" // .env.[mode].local

godotenv.Load(localM, mode, local, base)
```

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:

```gitignore
# local env files
.env.local
.env.*.local
```

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

0 comments on commit c5f2575

Please sign in to comment.