.env.go.local Jun 2026
.PHONY: build-prod build-prod: go build -o bin/server ./cmd/server
func LoadEnv() // Get the current working directory execPath, err := os.Getwd() if err != nil log.Fatal(err) .env.go.local
DB_PASSWORD=my_secret_password API_KEY=12345_67890 DEBUG_MODE=true Use code with caution. Copied to clipboard Update .gitignore : To prevent accidentally leaking your secrets, ensure your .gitignore file includes this line: .env*.local Use code with caution. Copied to clipboard How to Use it in Go The standard library "debug") : By naming convention
# .env PORT=8080 DB_DSN=postgres://user:pass@localhost:5432/mydb REDIS_ADDR=localhost:6379 LOG_LEVEL=info .env.go.local
// env/env.local.go //go:build local // +build local
func init() os.Setenv("DB_HOST", "localhost:5432") os.Setenv("API_KEY", "dev-12345") os.Setenv("LOG_LEVEL", "debug")
: By naming convention, these files are meant to be added to .gitignore to prevent sensitive credentials from being committed to version control .