Config parsing with env defaults and strict validation

12191
0

Config bugs are some of the most expensive production incidents because they vary by environment and can be hard to reproduce. I keep configuration in a typed struct, load it from environment variables, and validate it before the server starts. The validation step is the important part: fail fast with a clear message rather than booting with 0 values that cause weird behavior later. I also parse durations with time.ParseDuration so settings like HTTP_TIMEOUT=2s remain readable. When secrets are involved, I avoid printing them in logs and only log which required keys are missing. This snippet shows a pragmatic “no dependencies” approach, but the discipline scales to envconfig or a full config system later. Good config hygiene makes deploys boring.