.env.go.local
If your .env.go.local imports the same package it’s overriding, you get a cycle. Keep local configs in the same package but use init() only for os.Setenv, not for importing local structs.
VS Code and GoLand may not automatically respect build tags. Configure your settings.json: .env.go.local
"go.buildTags": "local"
While .env.go.local is ignored by Git, never commit real secrets. Use a secrets manager (e.g., Vault, AWS Secrets Manager, 1Password CLI) in production, and keep local secrets out of version control entirely. If your
Here’s the pattern that fits Go’s simplicity: Why go.local ? It’s explicit
Why go.local? It’s explicit, avoids collisions with other projects (Node, Python, etc.), and signals that this override file belongs to this Go service.
If you’ve worked on Go applications that interact with databases, APIs, or external services, you know the pain of managing configuration across different environments (local, staging, production). Hardcoding values is brittle, and using a single .env file often leads to accidental commits of secrets or messy overrides.
Enter .env.go.local – a lightweight, local-first environment file pattern that works beautifully with Go’s os.Getenv and popular packages like joho/godotenv.