diff --git a/config/config_center_config.go b/config/config_center_config.go
index e50fabd5558a84274a87afe6f78227b902cd10a9..84f307d455a35e76d8578dc6a4bd9367a3edb913 100644
--- a/config/config_center_config.go
+++ b/config/config_center_config.go
@@ -104,7 +104,7 @@ func (b *configCenter) toURL(baseConfig BaseConfig) (common.URL, error) {
return common.URL{}, perrors.New("Could not find out the remote ref config, name: " + remoteRef)
}
- newURL, err := rc.toURL(baseConfig.ConfigCenterConfig.Protocol)
+ newURL, err := rc.toURL()
if err == nil {
newURL.SetParams(baseConfig.ConfigCenterConfig.GetUrlMap())
}
@@ -126,7 +126,7 @@ func (b *configCenter) startConfigCenter(baseConfig BaseConfig) error {
}
func (b *configCenter) prepareEnvironment(baseConfig BaseConfig, configCenterUrl *common.URL) error {
- factory := extension.GetConfigCenterFactory(baseConfig.ConfigCenterConfig.Protocol)
+ factory := extension.GetConfigCenterFactory(configCenterUrl.Protocol)
dynamicConfig, err := factory.GetDynamicConfiguration(configCenterUrl)
config.GetEnvInstance().SetDynamicConfiguration(dynamicConfig)
if err != nil {
diff --git a/config/config_center_config_test.go b/config/config_center_config_test.go
index 3a08e013028a5567a056dc1095d6ecf7763bf6e8..05912a9fb9317736b54b3b0b92097d49eeb89af2 100644
--- a/config/config_center_config_test.go
+++ b/config/config_center_config_test.go
@@ -55,11 +55,10 @@ func TestStartConfigCenterWithRemoteRef(t *testing.T) {
return &config_center.MockDynamicConfigurationFactory{}
})
m := make(map[string]*RemoteConfig)
- m["mock"] = &RemoteConfig{Address: "172.0.0.1"}
+ m["mock"] = &RemoteConfig{Protocol: "mock", Address: "172.0.0.1"}
baseConfig = &BaseConfig{
Remotes: m,
ConfigCenterConfig: &ConfigCenterConfig{
- Protocol: "mock",
Group: "dubbo",
RemoteRef: "mock",
ConfigFile: "mockDubbo.properties",
diff --git a/config/remote_config.go b/config/remote_config.go
index 618313d7dc6374f291eb51d20cd38861762ff4a1..f1ee734aa72efa89dcfe93e04ca1b57ffd22951f 100644
--- a/config/remote_config.go
+++ b/config/remote_config.go
@@ -31,6 +31,7 @@ import (
// so that other module, like config center, registry could reuse the config
// but now, only metadata report, metadata service, service discovery use this structure
type RemoteConfig struct {
+ Protocol string `required:"true" yaml:"protocol" json:"protocol,omitempty"`
Address string `yaml:"address" json:"address,omitempty"`
TimeoutStr string `default:"5s" yaml:"timeout" json:"timeout,omitempty"`
Username string `yaml:"username" json:"username,omitempty" property:"username"`
@@ -58,11 +59,11 @@ func (rc *RemoteConfig) GetParam(key string, def string) string {
return param
}
-func (rc *RemoteConfig) toURL(protocol string) (common.URL, error) {
+func (rc *RemoteConfig) toURL() (common.URL, error) {
return common.NewURL(rc.Address,
common.WithUsername(rc.Username),
common.WithPassword(rc.Password),
common.WithLocation(rc.Address),
- common.WithProtocol(protocol),
+ common.WithProtocol(rc.Protocol),
)
}