What problem does it solve?
Viper-backed Go projects often fail to resolve the intended settings because config can come from multiple sources (flags, env vars, files, defaults, and optional remote KV) with a strict precedence order. This skill helps you avoid subtle misconfiguration by wiring the environment and flag bindings correctly and by unmarshaling into typed structs safely.
Core Features & Use Cases
- Layered precedence correctness: Ensures you understand how Viper decides which value wins across Set(), flags, env vars, config files, remote KV, and defaults.
- Reliable env var mapping for nested keys: Shows how to configure SetEnvPrefix, SetEnvKeyReplacer, and AutomaticEnv so keys like database.host map to APP_DATABASE_HOST.
- Safe struct decoding: Covers Unmarshal and mapstructure struct tags (including why time.Duration and other types may need decode hooks).
- Operational ergonomics: Handles optional config files via ConfigFileNotFoundError, supports sub-tree access with nil-aware guidance, and explains hot reload caveats with WatchConfig/OnConfigChange.
Quick Start
Tell the agent to configure Viper in your Go service so nested keys are correctly read from environment variables by applying prefix + key replacer + AutomaticEnv, while unmarshaling into your config structs using mapstructure tags.