Environment Config and Secrets
Twelve-factor config, env vars, and Docker secrets
12-factor app config
The 12-factor app methodology recommends storing configuration in environment variables, not in code or config files. This makes the app portable across dev, staging, and prod without code changes.
os.Getenv
Read environment variables with os.Getenv (returns "" if not set) or os.LookupEnv (returns value and presence bool):
port := os.Getenv("PORT")
if port == "" { port = "8080" }
dsn, ok := os.LookupEnv("DATABASE_URL")
if !ok { log.Fatal("DATABASE_URL not set") }All lessons in this course
- Multi-Stage Docker Builds for Go
- Environment Config and Secrets
- Docker Compose for Local Development
- Health Checks and Production Tuning