This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/3.0 by this push:
new ddc39a3 replace default config string with const value (#1182)
ddc39a3 is described below
commit ddc39a36f1b21cd0f1648dacd8c654808c262344
Author: Mulavar <[email protected]>
AuthorDate: Thu Apr 29 13:47:21 2021 +0800
replace default config string with const value (#1182)
* replace default config string with const value
* delete some duplicate keys
Co-authored-by: dongjianhui <[email protected]>
---
common/constant/default.go | 8 ++++++++
config/config_loader.go | 16 ++++++++--------
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/common/constant/default.go b/common/constant/default.go
index f52a3f0..bf9a19b 100644
--- a/common/constant/default.go
+++ b/common/constant/default.go
@@ -94,3 +94,11 @@ const (
DEFAULT_LOG_CONF_FILE_PATH = "../profiles/dev/log.yml"
DEFAULT_ROUTER_CONF_FILE_PATH = "../profiles/dev/router.yml"
)
+
+// default config value
+const (
+ DEFAULT_REGISTRY_ZK_ID = "demoZK"
+ DEFAULT_REGISTRY_ZK_PROTOCOL = ZOOKEEPER_KEY
+ DEFAULT_REGISTRY_ZK_TIMEOUT = "3s"
+ DEFAULT_REGISTRY_ZK_ADDRESS = "127.0.0.1:2181"
+)
diff --git a/config/config_loader.go b/config/config_loader.go
index 7f82b78..9934212 100644
--- a/config/config_loader.go
+++ b/config/config_loader.go
@@ -96,20 +96,20 @@ func DefaultInit() []LoaderInitOption {
// 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",
+ Protocol: constant.DEFAULT_REGISTRY_ZK_PROTOCOL,
+ TimeoutStr: constant.DEFAULT_REGISTRY_ZK_TIMEOUT,
+ Address: constant.DEFAULT_REGISTRY_ZK_ADDRESS,
}
switch target.(type) {
case *ProviderConfig:
p := target.(*ProviderConfig)
if len(p.Registries) == 0 {
- p.Registries["demoZK"] = registryConfig
+ p.Registries[constant.DEFAULT_REGISTRY_ZK_ID] =
registryConfig
}
if len(p.Protocols) == 0 {
- p.Protocols["dubbo"] = &ProtocolConfig{
- Name: "dubbo",
- Port: "20000",
+ p.Protocols[constant.DEFAULT_PROTOCOL] =
&ProtocolConfig{
+ Name: constant.DEFAULT_PROTOCOL,
+ Port: string(constant.DEFAULT_PORT),
}
}
if p.ApplicationConfig == nil {
@@ -118,7 +118,7 @@ func setDefaultValue(target interface{}) {
default:
c := target.(*ConsumerConfig)
if len(c.Registries) == 0 {
- c.Registries["demoZK"] = registryConfig
+ c.Registries[constant.DEFAULT_REGISTRY_ZK_ID] =
registryConfig
}
if c.ApplicationConfig == nil {
c.ApplicationConfig = NewDefaultApplicationConfig()