golang-spf13-viper

Configure Golang apps with spf13/viper's precedence, variables, flags, and hot reload.

Updated Jul 3, 2026
One-click install
npx skills add https://github.com/constzz/dates-app --skill golang-spf13-viper-constzz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-spf13-viper
Source: https://github.com/constzz/dates-app/tree/main/.agents/skills/golang-spf13-viper
Command: npx skills add https://github.com/constzz/dates-app --skill golang-spf13-viper-constzz

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill solves the problem of configuring Golang applications effectively using the spf13/viper library, offering guidance on layered precedence, flag management, environment variables, and configuration files.

Core Features & Use Cases

  • Layered Configuration: Offers guidance on managing configurations with precedence (flag > env > file > default).
  • Flag Management: Helps with BindPFlag/BindPFlags, SetEnvPrefix, and SetEnvKeyReplacer for robust CLI flag handling.
  • Hot Reload: Enables hot reload capabilities with WatchConfig and OnConfigChange for dynamic configuration updates.
  • Testing Isolation: Ensures test isolation by using viper.New() for per-test configuration instances.
  • Use Case: Imagine you're developing a Golang web service that requires complex configuration management. This Skill provides a structured approach to setting up viper, allowing you to maintain and modify configurations efficiently.

Quick Start

Initialize the skill for your project and refer to the skill documentation for detailed usage instructions.

Frequently Asked Questions about golang-spf13-viper

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I manage configuration precedence in Golang with viper?

Configuration precedence in viper follows a layered priority: flags override environment variables, which override config files, which override defaults. This ensures CLI inputs take highest priority while sensible defaults remain at the base of your Golang application.

How to bind CLI flags to environment variables in Golang using viper?

Binding CLI flags to environment variables requires using BindPFlag or BindPFlags alongside SetEnvPrefix and SetEnvKeyReplacer. This maps flag structures directly to environment variables for robust configuration handling.

Does viper support hot reload for Golang configuration files?

Viper supports hot reload functionality through the WatchConfig and OnConfigChange methods. This enables dynamic configuration updates in Golang applications without requiring a service restart when file values change.

What is the best way to isolate viper configurations for Golang testing?

Test isolation is achieved by using viper.New() to create per-test configuration instances. This prevents global state leakage between tests, ensuring each Golang test suite runs with its own independent configuration context.

Why does my viper environment variable override not work in Golang?

Environment variable overrides fail when BindPFlag is not used or SetEnvKeyReplacer is missing. Proper environment handling requires binding flags explicitly and setting key replacers to match your variable naming conventions.