This is an automated email from the ASF dual-hosted git repository.

zhangliang2022 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new ee50c27bb feat: add ENV_FILE var (#5399)
ee50c27bb is described below

commit ee50c27bbd8920cc94797a10063c25db2c4b73a3
Author: abeizn <[email protected]>
AuthorDate: Wed Jun 7 18:08:33 2023 +0800

    feat: add ENV_FILE var (#5399)
---
 backend/core/config/config_viper.go | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/backend/core/config/config_viper.go 
b/backend/core/config/config_viper.go
index 4302f2d7a..57e7ee303 100644
--- a/backend/core/config/config_viper.go
+++ b/backend/core/config/config_viper.go
@@ -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 {

Reply via email to