Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ _Example: test-specific env file_

```go
tmp, _ := os.MkdirTemp("", "envdoc")
_ = os.WriteFile(filepath.Join(tmp, ".env.testing"), []byte("PORT=9090\nAPP_DEBUG=0"), 0o644)
_ = os.WriteFile(filepath.Join(tmp, ".env.testing"), []byte("PORT=9090\nENV_DEBUG=0"), 0o644)
_ = os.Chdir(tmp)
_ = os.Setenv("APP_ENV", env.Testing)

Expand All @@ -456,7 +456,7 @@ env.Dump(os.Getenv("PORT"))
_Example: default .env on a host_

```go
_ = os.WriteFile(".env", []byte("SERVICE=api\nAPP_DEBUG=3"), 0o644)
_ = os.WriteFile(".env", []byte("SERVICE=api\nENV_DEBUG=3"), 0o644)
_ = env.LoadEnvFileIfExists()
env.Dump(os.Getenv("SERVICE"))

Expand Down
4 changes: 3 additions & 1 deletion docs/watcher.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash

go install github.com/bokwoon95/wgo@latest
if ! command -v wgo >/dev/null 2>&1; then
go install github.com/bokwoon95/wgo@latest
fi

echo "Watching for .go file changes to regenerate documentation..."

Expand Down
4 changes: 2 additions & 2 deletions examples/loadenvfileifexists/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {

// Example: test-specific env file
tmp, _ := os.MkdirTemp("", "envdoc")
_ = os.WriteFile(filepath.Join(tmp, ".env.testing"), []byte("PORT=9090\nAPP_DEBUG=0"), 0o644)
_ = os.WriteFile(filepath.Join(tmp, ".env.testing"), []byte("PORT=9090\nENV_DEBUG=0"), 0o644)
_ = os.Chdir(tmp)
_ = os.Setenv("APP_ENV", env.Testing)

Expand All @@ -25,7 +25,7 @@ func main() {
// #string "9090"

// Example: default .env on a host
_ = os.WriteFile(".env", []byte("SERVICE=api\nAPP_DEBUG=3"), 0o644)
_ = os.WriteFile(".env", []byte("SERVICE=api\nENV_DEBUG=3"), 0o644)
_ = env.LoadEnvFileIfExists()
env.Dump(os.Getenv("SERVICE"))

Expand Down
6 changes: 3 additions & 3 deletions loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var envLoaded = false
// Example: test-specific env file
//
// tmp, _ := os.MkdirTemp("", "envdoc")
// _ = os.WriteFile(filepath.Join(tmp, ".env.testing"), []byte("PORT=9090\nAPP_DEBUG=0"), 0o644)
// _ = os.WriteFile(filepath.Join(tmp, ".env.testing"), []byte("PORT=9090\nENV_DEBUG=0"), 0o644)
// _ = os.Chdir(tmp)
// _ = os.Setenv("APP_ENV", env.Testing)
//
Expand All @@ -52,7 +52,7 @@ var envLoaded = false
//
// Example: default .env on a host
//
// _ = os.WriteFile(".env", []byte("SERVICE=api\nAPP_DEBUG=3"), 0o644)
// _ = os.WriteFile(".env", []byte("SERVICE=api\nENV_DEBUG=3"), 0o644)
// _ = env.LoadEnvFileIfExists()
// env.Dump(os.Getenv("SERVICE"))
//
Expand Down Expand Up @@ -98,7 +98,7 @@ func LoadEnvFileIfExists() error {
}

// display loaded env files
if GetInt("APP_DEBUG", "0") >= 3 {
if GetInt("ENV_DEBUG", "0") >= 3 {
printLoadedEnvFiles(loadedFiles)
}

Expand Down
6 changes: 3 additions & 3 deletions loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestLoadEnvFileIfExists_testingEnv(t *testing.T) {
baseEnvFile := tempDir + "/.env"

// Write mock .env.testing
err := os.WriteFile(dotEnvFile, []byte("FAKE_ENV_TESTING=testing_value\nAPP_DEBUG=0"), 0644)
err := os.WriteFile(dotEnvFile, []byte("FAKE_ENV_TESTING=testing_value\nENV_DEBUG=0"), 0644)
if err != nil {
t.Fatalf("Failed to create temp .env.testing: %v", err)
}
Expand Down Expand Up @@ -87,10 +87,10 @@ func TestLoadEnvFileIfExists_WithDotEnvHostBranch(t *testing.T) {
})

tmp := t.TempDir()
if err := os.WriteFile(tmp+"/.env.testing", []byte("APP_DEBUG=3"), 0o644); err != nil {
if err := os.WriteFile(tmp+"/.env.testing", []byte("ENV_DEBUG=3"), 0o644); err != nil {
t.Fatalf("write .env.testing: %v", err)
}
if err := os.WriteFile(tmp+"/.env.host", []byte("HOST_BRANCH=hit\nAPP_DEBUG=3"), 0o644); err != nil {
if err := os.WriteFile(tmp+"/.env.host", []byte("HOST_BRANCH=hit\nENV_DEBUG=3"), 0o644); err != nil {
t.Fatalf("write .env.host: %v", err)
}

Expand Down