Created
March 23, 2025 16:03
-
-
Save metalagman/d0d3600af526ab0249f63664c9e5f4d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func initConfig() { | |
viper.SetConfigType("toml") | |
cobra.CheckErr(viper.ReadConfig(bytes.NewBuffer(defaultConfig))) | |
cobra.CheckErr(viper.BindPFlags(rootCmd.PersistentFlags())) | |
viper.SetEnvPrefix(envPrefix) | |
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) | |
cobra.CheckErr(viper.BindPFlag("log.level", rootCmd.PersistentFlags().Lookup("level"))) | |
cobra.CheckErr(viper.BindPFlag("log.pretty", rootCmd.PersistentFlags().Lookup("pretty"))) | |
viper.AutomaticEnv() | |
cobra.CheckErr(viper.Unmarshal(&cfg)) | |
cobra.CheckErr(validator.Validator.Struct(cfg)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment