You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by la...@apache.org on 2021/09/04 13:27:37 UTC

[dubbo-go] branch config-enhance updated: store zk value with base64. (#1440)

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

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


The following commit(s) were added to refs/heads/config-enhance by this push:
     new 90348d8  store zk value with base64. (#1440)
90348d8 is described below

commit 90348d8238cd49ccab3d70971d29b65c580bf38d
Author: Laurence <45...@users.noreply.github.com>
AuthorDate: Sat Sep 4 21:27:32 2021 +0800

    store zk value with base64. (#1440)
    
    * fix: add get dynamic configuration api
    
    * fix: change zk config center data to base64
---
 config/root_config.go           |  2 +-
 config_center/zookeeper/impl.go | 12 +++++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/config/root_config.go b/config/root_config.go
index 1279bf4..c928b8f 100644
--- a/config/root_config.go
+++ b/config/root_config.go
@@ -94,7 +94,7 @@ func (rc *RootConfig) Init() error {
 		return err
 	}
 	if err := rc.ConfigCenter.Init(rc); err != nil {
-		logger.Info("config center doesn't start.")
+		logger.Infof("config center doesn't start. error is %s", err)
 	}
 	if err := rc.Application.Init(rc); err != nil {
 		return err
diff --git a/config_center/zookeeper/impl.go b/config_center/zookeeper/impl.go
index b4a500c..b85d28a 100644
--- a/config_center/zookeeper/impl.go
+++ b/config_center/zookeeper/impl.go
@@ -18,6 +18,7 @@
 package zookeeper
 
 import (
+	"encoding/base64"
 	"strings"
 	"sync"
 )
@@ -114,8 +115,11 @@ func (c *zookeeperDynamicConfiguration) GetProperties(key string, opts ...config
 	if err != nil {
 		return "", perrors.WithStack(err)
 	}
-
-	return string(content), nil
+	decoded, err := base64.StdEncoding.DecodeString(string(content))
+	if err != nil {
+		return "", perrors.WithStack(err)
+	}
+	return string(decoded), nil
 }
 
 // GetInternalProperty For zookeeper, getConfig and getConfigs have the same meaning.
@@ -126,7 +130,9 @@ func (c *zookeeperDynamicConfiguration) GetInternalProperty(key string, opts ...
 // PublishConfig will put the value into Zk with specific path
 func (c *zookeeperDynamicConfiguration) PublishConfig(key string, group string, value string) error {
 	path := c.getPath(key, group)
-	err := c.client.CreateWithValue(path, []byte(value))
+	strbytes := []byte(value)
+	encoded := base64.StdEncoding.EncodeToString(strbytes)
+	err := c.client.CreateWithValue(path, []byte(encoded))
 	if err != nil {
 		return perrors.WithStack(err)
 	}