From 3896766f7d5260451da300cbf555e087a3b77740 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 24 Sep 2018 21:33:41 -0600 Subject: [PATCH] explicitly state env precedence and convention --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 4e8fcf2..d5370ec 100644 --- a/README.md +++ b/README.md @@ -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`