Merge remote-tracking branch 'upstream/1.5' into merge1.5to3.0
diff --git a/common/constant/default.go b/common/constant/default.go
index bbe022c..8afb5c7 100644
--- a/common/constant/default.go
+++ b/common/constant/default.go
@@ -87,3 +87,10 @@
const (
SERVICE_DISCOVERY_DEFAULT_GROUP = "DEFAULT_GROUP"
)
+
+const (
+ DEFAULT_PROVIDER_CONF_FILE_PATH = "../profiles/dev/server.yml"
+ DEFAULT_CONSUMER_CONF_FILE_PATH = "../profiles/dev/client.yml"
+ DEFAULT_LOG_CONF_FILE_PATH = "../profiles/dev/log.yml"
+ DEFAULT_ROUTER_CONF_FILE_PATH = "../profiles/dev/router.yml"
+)
diff --git a/common/logger/logger.go b/common/logger/logger.go
index 8519543..655b364 100644
--- a/common/logger/logger.go
+++ b/common/logger/logger.go
@@ -72,6 +72,9 @@
for len(fs.Args()) != 0 {
fs.Parse(fs.Args()[1:])
}
+ if *logConfFile == "" {
+ *logConfFile = constant.DEFAULT_LOG_CONF_FILE_PATH
+ }
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 1fd27d5..5834414 100644
--- a/config/config_loader.go
+++ b/config/config_loader.go
@@ -74,11 +74,25 @@
for len(fs.Args()) != 0 {
fs.Parse(fs.Args()[1:])
}
+ // If user did not set the environment variables or flags,
+ // we provide default value
+ if confConFile == "" {
+ confConFile = constant.DEFAULT_CONSUMER_CONF_FILE_PATH
+ }
+ if confProFile == "" {
+ confProFile = constant.DEFAULT_PROVIDER_CONF_FILE_PATH
+ }
+ if confRouterFile == "" {
+ confRouterFile = constant.DEFAULT_ROUTER_CONF_FILE_PATH
+ }
if errCon := ConsumerInit(confConFile); errCon != nil {
log.Printf("[consumerInit] %#v", errCon)
consumerConfig = nil
} else {
+ // Check if there are some important key fields missing,
+ // if so, we set a default value for it
+ setDefaultValue(consumerConfig)
// Even though baseConfig has been initialized, we override it
// because we think read from config file is correct config
baseConfig = &consumerConfig.BaseConfig
@@ -88,12 +102,48 @@
log.Printf("[providerInit] %#v", errPro)
providerConfig = nil
} else {
+ // Check if there are some important key fields missing,
+ // if so, we set a default value for it
+ setDefaultValue(providerConfig)
// Even though baseConfig has been initialized, we override it
// because we think read from config file is correct config
baseConfig = &providerConfig.BaseConfig
}
}
+// setDefaultValue set default value for providerConfig or consumerConfig if it is null
+func setDefaultValue(target interface{}) {
+ registryConfig := &RegistryConfig{
+ Protocol: "zookeeper",
+ TimeoutStr: "3s",
+ Address: "127.0.0.1:2181",
+ }
+ switch target.(type) {
+ case ProviderConfig:
+ p := target.(*ProviderConfig)
+ if len(p.Registries) == 0 {
+ p.Registries["demoZK"] = registryConfig
+ }
+ if len(p.Protocols) == 0 {
+ p.Protocols["dubbo"] = &ProtocolConfig{
+ Name: "dubbo",
+ Port: "20000",
+ }
+ }
+ if p.ApplicationConfig == nil {
+ p.ApplicationConfig = NewDefaultApplicationConfig()
+ }
+ default:
+ c := target.(*ConsumerConfig)
+ if len(c.Registries) == 0 {
+ c.Registries["demoZK"] = registryConfig
+ }
+ if c.ApplicationConfig == nil {
+ c.ApplicationConfig = NewDefaultApplicationConfig()
+ }
+ }
+}
+
func checkRegistries(registries map[string]*RegistryConfig, singleRegistry *RegistryConfig) {
if len(registries) == 0 && singleRegistry != nil {
registries[constant.DEFAULT_KEY] = singleRegistry