Skip to content

Commit

Permalink
feat: add ENV_FILE var (#5399)
Browse files Browse the repository at this point in the history
  • Loading branch information
abeizn authored Jun 7, 2023
1 parent 0c9311e commit ee50c27
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions backend/core/config/config_viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ func GetConfig() *viper.Viper {
func initConfig(v *viper.Viper) {
v.SetConfigName(getConfigName())
v.SetConfigType("env")
envPath := getEnvPath()
// AddConfigPath adds a path for Viper to search for the config file in.
v.AddConfigPath("./../../../../..")
v.AddConfigPath("./../../../..")
v.AddConfigPath("./../../..")
v.AddConfigPath("./../..")
v.AddConfigPath("./../")
v.AddConfigPath("./")
v.AddConfigPath(envPath)

if envFile := os.Getenv("ENV_FILE"); envFile != "" {
v.SetConfigFile(envFile)
} else {
v.SetConfigFile("./.env")
}
if _, err := os.Stat(v.ConfigFileUsed()); err == nil {
if err := v.ReadInConfig(); err != nil {
panic(fmt.Errorf("failed to read configuration file: %v", err))
}
}
}

func getConfigName() string {
Expand Down

0 comments on commit ee50c27

Please sign in to comment.