.env.go.local ((install)) -
Beyond .env: Why You Need a .env.go.local for Golang Services
If you’ve built any non-trivial Go service, you’ve likely used a .env file. It’s the standard way to manage configuration during local development.
But as your system grows—adding message queues, caching layers, dependent APIs, or multiple developers—one .env file often becomes a source of friction.
Enter .env.go.local. It’s not a new standard. It’s a pattern. And it has saved my team from configuration hell more than once.
What is .env.go.local?
At its core, .env.go.local is a naming convention—a hybrid between a configuration file and a Go source file. Unlike standard .env files which are parsed at runtime, .env.go.local is typically a Go package that exports variables, or a structured file that is read into your main.go exclusively during development. .env.go.local
Pitfall 2: Import Cycles
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.
Real-World Example
Let’s say your team’s .env uses a shared local Redis. You’re debugging a race condition and need a clean Redis instance on a different port.
Your .env.go.local:
REDIS_ADDR=localhost:6380
LOG_LEVEL=debug
The running service will use LOG_LEVEL=debug and REDIS_ADDR=localhost:6380, but still take PORT and DB_DSN from .env.
No changes committed. No fighting with git. No environment pollution.
A Note on Security
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. Beyond
1. The Concept: Why .env.go.local?
Standard .env files are loaded by libraries like godotenv. Naming a file .env.go.local suggests a specific intent:
- Scope: It is for the Go application specifically (useful if you have Node.js or Python scripts in the same repo).
- Environment: It is for local development only (overrides production values).
- Security: It keeps sensitive data out of version control.
Mastering Environment Configuration in Go: The Power of .env.go.local
Pitfall 3: IDE Integration
VS Code and GoLand may not automatically respect build tags. Configure your settings.json:
"go.buildTags": "local"