.env.go.local ((free)) -

go run main.go Add this to your Makefile for convenience:

While not an official Go standard library feature, the pattern of using a .env.go.local file has emerged as a best practice among elite Go teams. It bridges the gap between the inflexibility of hardcoded constants and the chaos of global environment variables.

Run tests with:

Introduction: The Configuration Conundrum Every seasoned Go developer knows the pain. You have your config.go file, your os.Getenv calls scattered everywhere, and a bulky .env file that works perfectly on your laptop but breaks catastrophically on your colleague’s machine because their API key has different permissions.

//go:build local // +build local package config .env.go.local

Enter the unsung hero of localized Go configuration: .

func init() os.Setenv("DB_HOST", "localhost:5432") os.Setenv("API_KEY", "dev-12345") os.Setenv("LOG_LEVEL", "debug") go run main

func getEnvAsInt(key string, fallback int) int if val, err := strconv.Atoi(os.Getenv(key)); err == nil return val