go-viper
Installation
SKILL.md
Use this skill to produce a clean Viper setup that reads configuration from file, flags, and environment with Viper's normal precedence:
- explicit
Set - flags
- environment variables
- config file
- remote key/value store
- defaults
Core approach
- Prefer
viper.New()over the package global; build one configured instance and pass it where needed. - Define a typed
Configstruct and unmarshal into it after all defaults, file paths, env bindings, and flag bindings are configured. - Keep configuration bootstrap in one place such as
internal/configorpkg/configwith aLoad(...)function. - Treat the config file as optional only when the app design allows it; otherwise return a clear error.
- Bind flags and env explicitly for important keys, and use
AutomaticEnv()plus an env key replacer for the general case.