0Pricing
Go Academy · Lesson

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

  1. Multi-Stage Docker Builds for Go
  2. Environment Config and Secrets
  3. Docker Compose for Local Development
  4. Health Checks and Production Tuning
← Back to Go Academy