From cf3acfdc6e8d5ae66ea59307d6073fd6d7f415a1 Mon Sep 17 00:00:00 2001
From: cjp <cjp_ca@163.com>
Date: Tue, 2 Feb 2021 00:46:11 +0800
Subject: [PATCH] add read configuration from the command line when start

---
 common/logger/logger.go | 14 ++++++++------
 config/config_loader.go | 12 +++++++++---
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/common/logger/logger.go b/common/logger/logger.go
index 4a2f07cb3..b763e3f44 100644
--- a/common/logger/logger.go
+++ b/common/logger/logger.go
@@ -18,6 +18,7 @@
 package logger
 
 import (
+	"flag"
 	"io/ioutil"
 	"log"
 	"os"
@@ -32,10 +33,6 @@ import (
 	"gopkg.in/yaml.v2"
 )
 
-import (
-	"github.com/apache/dubbo-go/common/constant"
-)
-
 var (
 	logger Logger
 )
@@ -64,8 +61,13 @@ func init() {
 	if logger != nil {
 		return
 	}
-	logConfFile := os.Getenv(constant.APP_LOG_CONF_FILE)
-	err := InitLog(logConfFile)
+	fs := flag.NewFlagSet("log_config", flag.ContinueOnError)
+	logConfFile := fs.String("logConf", "", "default log config path")
+	fs.Parse(os.Args[1:])
+	for len(fs.Args()) != 0{
+		fs.Parse(fs.Args()[1:])
+	}
+	err := InitLog(*logConfFile)
 	if err != nil {
 		log.Printf("[InitLog] warn: %v", err)
 	}
diff --git a/config/config_loader.go b/config/config_loader.go
index 35910981d..3d586907a 100644
--- a/config/config_loader.go
+++ b/config/config_loader.go
@@ -18,6 +18,7 @@
 package config
 
 import (
+	"flag"
 	"fmt"
 	"log"
 	"os"
@@ -63,9 +64,14 @@ func init() {
 		confProFile string
 	)
 
-	confConFile = os.Getenv(constant.CONF_CONSUMER_FILE_PATH)
-	confProFile = os.Getenv(constant.CONF_PROVIDER_FILE_PATH)
-	confRouterFile = os.Getenv(constant.CONF_ROUTER_FILE_PATH)
+	fs := flag.NewFlagSet("config_loader", flag.ContinueOnError)
+	fs.StringVar(&confConFile, "conConf", "", "default client config path")
+	fs.StringVar(&confProFile, "proConf", "", "default server config path")
+	fs.StringVar(&confRouterFile, "rouConf", "", "default router config path")
+	fs.Parse(os.Args[1:])
+	for len(fs.Args()) != 0{
+		fs.Parse(fs.Args()[1:])
+	}
 
 	if errCon := ConsumerInit(confConFile); errCon != nil {
 		log.Printf("[consumerInit] %#v", errCon)
-- 
GitLab