Install any skill in seconds. Free to start, no credit card required.
Get Started Free →samber/golang-spf13-viper
Golang configuration library using spf13/viper — layered precedence (flag > env > file > KV > default), BindPFlag/BindPFlags, SetEnvPrefix + SetEnvKeyReplacer + AutomaticEnv, ReadInConfig + ConfigFileNotFoundError, Unmarshal + mapstructure struct tags, Sub for sub-trees, WatchConfig + OnConfigChange for hot reload, viper.New() for test isolation, and remote KV integration. Apply when using or adopting spf13/viper, or when the codebase imports `github.com/spf13/viper`. For CLI command structure a
Passed 22 of 22 test cases with the skill, and 21 of 22 without it.
1 fixed21 passed either way0 still failing0 broke
Tokens, turns and time describe resource use, not a dollar price.
A test case the skill fixed. Same model, same prompt, with and without the skill.
Can you show me how to define Go struct types and write the code to load configuration sections into those structs using Viper? I have nested configuration blocks like `database` and `redis` with snake_case field names in the YAML file, and I want to parse specific sub-trees safely into my typed application struct.
| Checked | Without skill | With skill |
|---|---|---|
| uses explicit mapstructure struct tags for mapping snake_case fields | Passed | Passed |
| uses UnmarshalKey instead of Sub for parsing sub-trees safely | Missed | Passed |
| checks for ConfigFileNotFoundError with errors.As when calling ReadInConfig | Missed | Passed |
The instructions your model reads when the skill loads.
Persona: You are a Go engineer who treats configuration as a layered system. Flag beats env beats file beats default — and you bind every key so all four layers stay reachable through one API.
Viper resolves configuration values from multiple sources in a fixed precedence order. It has no user-facing surface — it doesn't define commands or flags. Its job is to answer "what is the value of key X right now?" by walking its source layers from highest to lowest priority.
Official Resources:
This skill is not exhaustive — refer to library documentation and code examples for more information:
samber/cc-skills-golang@golang-pkg-go-dev skill (godig), preferred over Context7 for Go package facts.samber/cc-skills-golang@golang-gopls skill (gopls).go get github.com/spf13/viper@latest
Cobra owns the command tree — subcommands, flags, arg validation, completions. Viper owns configuration resolution — it answers "what is the value of key X?" by walking its source layers, with no user-facing surface of its own: it is purely a key-value resolver.
PersistentPreRunE via BindPFlag.→ See samber/cc-skills-golang@golang-spf13-cobra for the cobra side of this integration.
Viper resolves a key by walking sources in this order (first set value wins):
1. explicit Set() — viper.Set("key", val) highest priority
2. flag — bound pflag.Flag
3. env var — BindEnv / AutomaticEnv
4. config file — ReadInConfig / MergeInConfig
test cases passed, vs 21 / 22 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.