Skip to content

Instantly share code, notes, and snippets.

@BNPrashanth
Created September 9, 2019 10:01
Show Gist options
  • Save BNPrashanth/7ff846fb52d35f985ad04435e8cd9e11 to your computer and use it in GitHub Desktop.
Save BNPrashanth/7ff846fb52d35f985ad04435e8cd9e11 to your computer and use it in GitHub Desktop.
package configs
import (
"fmt"
"github.com/spf13/viper"
)
/*
InitializeViper Function initializes viper to read config.yml file and environment variables in the application.
*/
func InitializeViper() {
// Set the file name of the configurations file
viper.SetConfigName("config")
// Set the path to look for the configurations file
viper.AddConfigPath(".")
// Enable VIPER to read Environment Variables
viper.AutomaticEnv()
viper.SetConfigType("yml")
if err := viper.ReadInConfig(); err != nil {
fmt.Printf("Error reading config file, %s", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment