From c02b17e524b776609a6a7babaf56c7b3a45ef956 Mon Sep 17 00:00:00 2001 From: Jonson Petard <41122242+greenhat616@users.noreply.github.com> Date: Thu, 14 Sep 2023 22:29:17 +0800 Subject: [PATCH] chore(config): reading env vars --- prestart/init_config_driver.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/prestart/init_config_driver.go b/prestart/init_config_driver.go index e7f559d..4d33850 100644 --- a/prestart/init_config_driver.go +++ b/prestart/init_config_driver.go @@ -16,6 +16,12 @@ func initConfigDriver() { logger := logging.GetLogger() defer logger.Sync() config.SetDefault() + + // Parse env config + viper.SetEnvPrefix("moe") // like: MOE_PORT=8000 + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + viper.AutomaticEnv() + // Set default viper information viper.SetConfigName("config") if config.File != "" { @@ -54,10 +60,7 @@ func initConfigDriver() { logger.Warn("[init] No config file detected, reading config from env.") } } - // Parse env config - viper.SetEnvPrefix("moe") // like: MOE_PORT=8000 - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) - viper.AutomaticEnv() + logger.Debug("[init] config is parsed.", zap.String("config_file_used", viper.ConfigFileUsed()), zap.Any("settings", viper.AllSettings()),