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
| viper.AutomaticEnv() |
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
| err := viper.WriteConfigAs("path/to/ConfigFile.yaml") | |
| if err != nil { | |
| return nil, err | |
| } | |
| err := viper.SafeWriteConfig("path/to/ConfigFile.yaml") | |
| if err != nil { | |
| return nil, err | |
| } |
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
| err := viper.WriteConfig() | |
| if err != nil { | |
| return nil, err | |
| } | |
| err := viper.SafeWriteConfig() | |
| if err != nil { | |
| return nil, err | |
| } |
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
| viper.OnConfigChange(func(e fsnotify.Event) { | |
| // do something whenever a configguration changes | |
| }) |
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
| viper.WatchConfig() |
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
| allSettings := viper.AllSettings() | |
| allKeys := viper.AllKeys() |
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
| if(viper.IsSet("key")) { | |
| // do something | |
| } |
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
| string := viper.GetString("key") | |
| int := viper.GetInt("int") | |
| bool := viper.GetBool("key") | |
| duration := viper.GetDuration("key") | |
| stringMap := viper.GetStringMap("key") |
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
| viper.SetDefault("logs", true) | |
| viper.SetDefault("port", 8080) | |
| viper.SetDefault("db", "mongodb://localhost:27017") |
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
| err := viper.ReadInConfig() | |
| if err != nil { | |
| panic(fmt.Errorf("Fatal error config file: %w \n", err)) | |
| } |