LabscoMCP early access ↗

A setting can come from a command-line flag, an environment variable, a config file or a built-in default — viper decides which one wins, in that order, every time it is asked.

WHEN TO USE

SCOPE

USE FOR

  • Resolve a config value from flags, env vars, a config file, and defaults in one call.
  • Wire SetEnvPrefix, SetEnvKeyReplacer, and AutomaticEnv together for nested env keys.
  • Bind a cobra flag to viper so it overrides the config file and defaults.
  • Unmarshal resolved configuration into a struct with mapstructure tags.
  • Reload configuration at runtime when the config file changes on disk.
  • Isolate viper state between tests with a fresh viper.New() instance.

NOT FOR

  • Defining commands, flags, or a CLI's user-facing surface — that's cobra's job.
golang-spf13-viper — Agent skill by samber | Labsco