golang-spf13-viper
CommunityBuild layered Go config with safe defaults.
System Documentation
What problem does it solve?
It prevents broken or surprising configuration behavior in Go services by making spf13/viper’s precedence rules predictable and correctly wired (flags, env vars, files, defaults, and optional remote KV).
Core Features & Use Cases
- Layered precedence that behaves correctly: Ensures explicit Set and bound flags win over env vars and config files, and that defaults only apply when nothing else provides a value.
- Correct env var mapping for nested keys: Makes nested viper keys resolve from environment variables by using SetEnvPrefix, SetEnvKeyReplacer, and AutomaticEnv together.
- Production-safe struct decoding and testing patterns: Uses mapstructure tags, supports hot reload with validation, and avoids test pollution by using viper.New() per test.
- Unmarshal reliability for tricky types: Handles duration and weak/typed decoding issues via decode hooks and DecoderConfig options.
Quick Start
Ask your AI coding agent to wire spf13/viper in your Go app so that nested keys (like database.host) resolve from env vars using prefix + key replacer, flags are bound before command execution, missing config files are handled gracefully, and unmarshalling uses mapstructure tags with proper decode hooks.
Dependency Matrix
Required Modules
None requiredComponents
💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: golang-spf13-viper Download link: https://github.com/vanstinator/semantic-search/archive/main.zip#golang-spf13-viper Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.