Skip to content

Instantly share code, notes, and snippets.

@madflojo
Last active May 15, 2021 18:55
Show Gist options
  • Save madflojo/7dd72ce95cac7b14280f1f799463364f to your computer and use it in GitHub Desktop.
Save madflojo/7dd72ce95cac7b14280f1f799463364f to your computer and use it in GitHub Desktop.
Viper Article - Adding Files
// Load Config
cfg.AddConfigPath("./conf")
cfg.SetEnvPrefix("app")
cfg.AllowEmptyEnv(true)
cfg.AutomaticEnv()
err := cfg.ReadInConfig()
if err != nil {
switch err.(type) {
case viper.ConfigFileNotFoundError:
log.Warnf("No Config file found, loaded config from Environment - Default path ./conf")
default:
log.Fatalf("Error when Fetching Configuration - %s", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment