Stage 1 · Code
Capstone — Ship a Real Tool
Flags & Environment Config
Load configuration from flags, environment variables, and defaults — with clear validation and startup error messages.
Config Struct
Collect all configuration into a single struct. This makes configuration explicit, testable, and easy to pass through the application without global variables.
Environment Variables
os.LookupEnv returns the value and a boolean indicating whether the variable was set. This lets you distinguish 'not set' from 'set to empty string'.
Flags Override Env
The standard precedence is: defaults → environment variables → flags. Flags win because they are explicit. Apply env first, then parse flags, then let flags override env.
Validation and Startup Errors
Validate configuration before starting the server. Fast-fail at startup with clear messages — a missing config found at startup is far cheaper than one found under load.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.