zwxi 10 months ago
parent
commit
1cf161ca3d
1 changed files with 13 additions and 11 deletions
  1. 13 11
      utils/config.go

+ 13 - 11
utils/config.go

@@ -554,17 +554,19 @@ func init() {
 
 	ErrMsgConfigFile = config["err_msg_config_file"]
 
-	viper.SetConfigFile(ErrMsgConfigFile)
-	err = viper.ReadInConfig()
-	if err != nil {
-		if _, ok := err.(viper.ConfigFileNotFoundError); ok {
-			fmt.Println(errors.New("config file not found"))
-			panic(any("config file not found"))
-		} else {
-			fmt.Println(errors.New("config file was found but another error was produced err:" + err.Error()))
-			panic(any("config file was found but another error was produced err:" + err.Error()))
+	if ErrMsgConfigFile != "" {
+		viper.SetConfigFile(ErrMsgConfigFile)
+		err = viper.ReadInConfig()
+		if err != nil {
+			if _, ok := err.(viper.ConfigFileNotFoundError); ok {
+				fmt.Println(errors.New("config file not found"))
+				panic(any("config file not found"))
+			} else {
+				fmt.Println(errors.New("config file was found but another error was produced err:" + err.Error()))
+				panic(any("config file was found but another error was produced err:" + err.Error()))
+			}
+			return
 		}
-		return
+		ViperConfig = viper.GetViper()
 	}
-	ViperConfig = viper.GetViper()
 }