viper-go-setup

Solid

Set up Viper for Go configuration management with file, env, and flag binding.

AI & Automation 814 stars 53 forks Updated today MIT

Install

View on GitHub

Quality Score: 93/100

Stars 20%
97
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
56
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Viper Go Setup Set up Viper for Go configuration management. ## Generated Patterns ```go package config import ( "github.com/spf13/viper" "github.com/spf13/cobra" ) type Config struct { Server ServerConfig `mapstructure:"server"` Database DatabaseConfig `mapstructure:"database"` } type ServerConfig struct { Host string `mapstructure:"host"` Port int `mapstructure:"port"` } func InitConfig(cfgFile string) (*Config, error) { if cfgFile != "" { viper.SetConfigFile(cfgFile) } else { viper.SetConfigName("config") viper.SetConfigType("yaml") viper.AddConfigPath(".") viper.AddConfigPath("$HOME/.myapp") } viper.AutomaticEnv() viper.SetEnvPrefix("MYAPP") if err := viper.ReadInConfig(); err != nil { if _, ok := err.(viper.ConfigFileNotFoundError); !ok { return nil, err } } var cfg Config if err := viper.Unmarshal(&cfg); err != nil { return nil, err } return &cfg, nil } ``` ## Target Processes - configuration-management-system - cli-application-bootstrap

Details

Author
a5c-ai
Repository
a5c-ai/babysitter
Created
4 months ago
Last Updated
today
Language
JavaScript
License
MIT

Related Skills