Skip to content

Commit

Permalink
Merge pull request #1039 from cjphaha/develop
Browse files Browse the repository at this point in the history
Ftr: read configuration path from the command line when start
  • Loading branch information
AlexStocks authored Feb 3, 2021
2 parents 49daddf + f0b01c6 commit 28a1d7a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 9 additions & 2 deletions common/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package logger

import (
"flag"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -64,8 +65,14 @@ func init() {
if logger != nil {
return
}
logConfFile := os.Getenv(constant.APP_LOG_CONF_FILE)
err := InitLog(logConfFile)

fs := flag.NewFlagSet("log", flag.ContinueOnError)
logConfFile := fs.String("logConf", os.Getenv(constant.APP_LOG_CONF_FILE), "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)
}
Expand Down
12 changes: 9 additions & 3 deletions config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package config

import (
"flag"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -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", flag.ContinueOnError)
fs.StringVar(&confConFile, "conConf", os.Getenv(constant.CONF_CONSUMER_FILE_PATH), "default client config path")
fs.StringVar(&confProFile, "proConf", os.Getenv(constant.CONF_PROVIDER_FILE_PATH), "default server config path")
fs.StringVar(&confRouterFile, "rouConf", os.Getenv(constant.CONF_ROUTER_FILE_PATH), "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)
Expand Down

0 comments on commit 28a1d7a

Please sign in to comment.