In your main.go , load both files, ensuring the local one overrides the shared one:
"database": "primary": "host": "localhost", "port": 5432
: Already set on the host machine (highest priority). .env.go.local : Machine-specific Go overrides (ignores Git). .env.local : General local overrides (ignores Git). .env.go.local
To ensure your local configurations stay local, your .gitignore should look like this:
DB_USER=my_local_user DB_PASSWORD=supersecret LOG_LEVEL=debug In your main
# Standard environment files .env.local .env.development.local .env.test.local .env.production.local # Go-specific local environment overrides .env.go.local Use code with caution. 2. Ship a .env.example File
# Log files *.log # Go binaries main # Environment overrides .env.local .env.go.local Use code with caution. Use .env.example as a Blueprint To ensure your local configurations stay local, your
The name follows a tiered naming convention popularized by frameworks like Create React App and Docker: : The base configuration.
// Validate required fields if cfg.DBURL == "" return nil, fmt.Errorf("DATABASE_URL is required")
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.