You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/06/23 11:59:47 UTC

[dubbo-go] branch 1.5 updated: Support more parameter Settings (#1272)

This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch 1.5
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/1.5 by this push:
     new f9bc0a6  Support more parameter Settings (#1272)
f9bc0a6 is described below

commit f9bc0a6e948b4edc4192d7b2d8dee4fed6a50710
Author: 赵云兴 <23...@qq.com>
AuthorDate: Wed Jun 23 19:59:39 2021 +0800

    Support more parameter Settings (#1272)
    
    * Support more parameter Settings
    
    * 修改拼写问题
    
    * up:AppId > AppID
---
 common/constant/key.go            | 23 ++++++++++++++++-------
 config/config_center_config.go    | 37 ++++++++++++++++++++++---------------
 config_center/apollo/impl_test.go |  2 +-
 config_center/nacos/client.go     | 21 ++++++++++++++-------
 4 files changed, 53 insertions(+), 30 deletions(-)

diff --git a/common/constant/key.go b/common/constant/key.go
index 8e5c57d..8924186 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -134,13 +134,14 @@ const (
 )
 
 const (
-	CONFIG_NAMESPACE_KEY  = "config.namespace"
-	CONFIG_GROUP_KEY      = "config.group"
-	CONFIG_APP_ID_KEY     = "config.appId"
-	CONFIG_CLUSTER_KEY    = "config.cluster"
-	CONFIG_CHECK_KEY      = "config.check"
-	CONFIG_TIMEOUT_KET    = "config.timeout"
-	CONFIG_LOG_DIR_KEY    = "config.logDir"
+	CONFIG_NAMESPACE_KEY  = "namespace"
+	CONFIG_GROUP_KEY      = "group"
+	CONFIG_APP_ID_KEY     = "appId"
+	CONFIG_CLUSTER_KEY    = "cluster"
+	CONFIG_TIMEOUT_KEY    = "timeout"
+	CONFIG_USERNAME_KEY   = "username"
+	CONFIG_PASSWORD_KEY   = "password"
+	CONFIG_LOG_DIR_KEY    = "logDir"
 	CONFIG_VERSION_KEY    = "configVersion"
 	COMPATIBLE_CONFIG_KEY = "compatible_config"
 )
@@ -169,6 +170,7 @@ const (
 	NACOS_DEFAULT_ROLETYPE       = 3
 	NACOS_CACHE_DIR_KEY          = "cacheDir"
 	NACOS_LOG_DIR_KEY            = "logDir"
+	NACOS_BEAT_INTERVAL_KEY      = "beatInterval"
 	NACOS_ENDPOINT               = "endpoint"
 	NACOS_SERVICE_NAME_SEPARATOR = ":"
 	NACOS_CATEGORY_KEY           = "category"
@@ -178,6 +180,13 @@ const (
 	NACOS_PASSWORD               = "password"
 	NACOS_USERNAME               = "username"
 	NACOS_NOT_LOAD_LOCAL_CACHE   = "nacos.not.load.cache"
+	NACOS_APP_NAME_KEY           = "appName"
+	NACOS_REGION_ID_KEY          = "regionId"
+	NACOS_ACCESS_KEY             = "access"
+	NACOS_SECRET_KEY             = "secret"
+	NACOS_OPEN_KMS_KEY           = "kms"
+	NACOS_UPDATE_THREAD_NUM_KEY  = "updateThreadNum"
+	NACOS_LOG_LEVEL_KEY          = "logLevel"
 )
 
 const (
diff --git a/config/config_center_config.go b/config/config_center_config.go
index 59d36fb..22ffce9 100644
--- a/config/config_center_config.go
+++ b/config/config_center_config.go
@@ -45,20 +45,20 @@ import (
 // ConfigCenter has currently supported Zookeeper, Nacos, Etcd, Consul, Apollo
 type ConfigCenterConfig struct {
 	//context       context.Context
-	Protocol      string `required:"true"  yaml:"protocol"  json:"protocol,omitempty"`
-	Address       string `yaml:"address" json:"address,omitempty"`
-	Cluster       string `yaml:"cluster" json:"cluster,omitempty"`
-	Group         string `default:"dubbo" yaml:"group" json:"group,omitempty"`
-	Username      string `yaml:"username" json:"username,omitempty"`
-	Password      string `yaml:"password" json:"password,omitempty"`
-	LogDir        string `yaml:"log_dir" json:"log_dir,omitempty"`
-	ConfigFile    string `default:"dubbo.properties" yaml:"config_file"  json:"config_file,omitempty"`
-	Namespace     string `default:"dubbo" yaml:"namespace"  json:"namespace,omitempty"`
-	AppConfigFile string `default:"dubbo.properties" yaml:"app_config_file"  json:"app_config_file,omitempty"`
-	AppId         string `default:"dubbo" yaml:"app_id"  json:"app_id,omitempty"`
-	TimeoutStr    string `yaml:"timeout"  json:"timeout,omitempty"`
-	RemoteRef     string `required:"false"  yaml:"remote_ref"  json:"remote_ref,omitempty"`
-	//timeout       time.Duration
+	Protocol      string            `required:"true"  yaml:"protocol"  json:"protocol,omitempty"`
+	Address       string            `yaml:"address" json:"address,omitempty"`
+	Cluster       string            `yaml:"cluster" json:"cluster,omitempty"`
+	Group         string            `default:"dubbo" yaml:"group" json:"group,omitempty"`
+	Username      string            `yaml:"username" json:"username,omitempty"`
+	Password      string            `yaml:"password" json:"password,omitempty"`
+	LogDir        string            `yaml:"log_dir" json:"log_dir,omitempty"`
+	ConfigFile    string            `default:"dubbo.properties" yaml:"config_file"  json:"config_file,omitempty"`
+	Namespace     string            `default:"dubbo" yaml:"namespace"  json:"namespace,omitempty"`
+	AppConfigFile string            `default:"dubbo.properties" yaml:"app_config_file"  json:"app_config_file,omitempty"`
+	AppID         string            `default:"dubbo" yaml:"app_id"  json:"app_id,omitempty"`
+	TimeoutStr    string            `yaml:"timeout"  json:"timeout,omitempty"`
+	RemoteRef     string            `required:"false"  yaml:"remote_ref"  json:"remote_ref,omitempty"`
+	Parameters    map[string]string `yaml:"parameters"  json:"parameters,omitempty"`
 }
 
 // UnmarshalYAML unmarshals the ConfigCenterConfig by @unmarshal function
@@ -76,8 +76,15 @@ func (c *ConfigCenterConfig) GetURLMap() url.Values {
 	urlMap.Set(constant.CONFIG_NAMESPACE_KEY, c.Namespace)
 	urlMap.Set(constant.CONFIG_GROUP_KEY, c.Group)
 	urlMap.Set(constant.CONFIG_CLUSTER_KEY, c.Cluster)
-	urlMap.Set(constant.CONFIG_APP_ID_KEY, c.AppId)
+	urlMap.Set(constant.CONFIG_APP_ID_KEY, c.AppID)
 	urlMap.Set(constant.CONFIG_LOG_DIR_KEY, c.LogDir)
+	urlMap.Set(constant.CONFIG_USERNAME_KEY, c.Username)
+	urlMap.Set(constant.CONFIG_PASSWORD_KEY, c.Password)
+	urlMap.Set(constant.CONFIG_TIMEOUT_KEY, c.TimeoutStr)
+
+	for key, val := range c.Parameters {
+		urlMap.Set(key, val)
+	}
 	return urlMap
 }
 
diff --git a/config_center/apollo/impl_test.go b/config_center/apollo/impl_test.go
index 4118cc4..43e306e 100644
--- a/config_center/apollo/impl_test.go
+++ b/config_center/apollo/impl_test.go
@@ -189,7 +189,7 @@ func initMockApollo(t *testing.T) *apolloConfiguration {
 	c := &config.BaseConfig{ConfigCenterConfig: &config.ConfigCenterConfig{
 		Protocol:  "apollo",
 		Address:   "106.12.25.204:8080",
-		AppId:     "testApplication_yang",
+		AppID:     "testApplication_yang",
 		Cluster:   "dev",
 		Namespace: "mockDubbog",
 	}}
diff --git a/config_center/nacos/client.go b/config_center/nacos/client.go
index 4d94043..ba51e45 100644
--- a/config_center/nacos/client.go
+++ b/config_center/nacos/client.go
@@ -86,10 +86,10 @@ func ValidateNacosClient(container nacosClientFacade, opts ...option) error {
 	}
 
 	url := container.GetURL()
-	timeout, err := time.ParseDuration(url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT))
+	timeout, err := time.ParseDuration(url.GetParam(constant.CONFIG_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT))
 	if err != nil {
 		logger.Errorf("invalid timeout config %+v,got err %+v",
-			url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT), err)
+			url.GetParam(constant.CONFIG_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT), err)
 		return perrors.WithMessagef(err, "newNacosClient(address:%+v)", url.Location)
 	}
 	nacosAddresses := strings.Split(url.Location, ",")
@@ -165,14 +165,21 @@ func initNacosConfigClient(nacosAddrs []string, timeout time.Duration, url *comm
 		"serverConfigs": svrConfList,
 		"clientConfig": nacosconst.ClientConfig{
 			TimeoutMs:           uint64(int32(timeout / time.Millisecond)),
-			ListenInterval:      uint64(int32(timeout / time.Millisecond)),
-			NotLoadCacheAtStart: true,
-			LogDir:              url.GetParam(constant.NACOS_LOG_DIR_KEY, ""),
-			CacheDir:            url.GetParam(constant.NACOS_CACHE_DIR_KEY, ""),
+			BeatInterval:        url.GetParamInt(constant.NACOS_BEAT_INTERVAL_KEY, 5000),
+			NamespaceId:         url.GetParam(constant.NACOS_NAMESPACE_ID, ""),
+			AppName:             url.GetParam(constant.NACOS_APP_NAME_KEY, ""),
 			Endpoint:            url.GetParam(constant.NACOS_ENDPOINT, ""),
+			RegionId:            url.GetParam(constant.NACOS_REGION_ID_KEY, ""),
+			AccessKey:           url.GetParam(constant.NACOS_ACCESS_KEY, ""),
+			SecretKey:           url.GetParam(constant.NACOS_SECRET_KEY, ""),
+			OpenKMS:             url.GetParamBool(constant.NACOS_OPEN_KMS_KEY, false),
+			CacheDir:            url.GetParam(constant.NACOS_CACHE_DIR_KEY, ""),
+			UpdateThreadNum:     url.GetParamByIntValue(constant.NACOS_UPDATE_THREAD_NUM_KEY, 20),
+			NotLoadCacheAtStart: url.GetParamBool(constant.NACOS_NOT_LOAD_LOCAL_CACHE, true),
 			Username:            url.GetParam(constant.NACOS_USERNAME, ""),
 			Password:            url.GetParam(constant.NACOS_PASSWORD, ""),
-			NamespaceId:         url.GetParam(constant.NACOS_NAMESPACE_ID, ""),
+			LogDir:              url.GetParam(constant.NACOS_LOG_DIR_KEY, ""),
+			LogLevel:            url.GetParam(constant.NACOS_LOG_LEVEL_KEY, "info"),
 		},
 	})
 }