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 a3569bf  fix: add config center metadata able (#1253)
a3569bf is described below

commit a3569bf03d4476b8ef71a550befd1cb10274a884
Author: Laurence <[email protected]>
AuthorDate: Tue Jun 15 10:34:01 2021 +0800

    fix: add config center metadata able (#1253)
---
 common/constant/key.go             |  3 +++
 config/base_config.go              | 13 ++++++++-----
 config/config_loader.go            | 20 ++++++++++++++------
 config/consumer_config.go          |  2 +-
 config/metadata_report_config.go   |  4 ++--
 config/provider_config.go          |  2 +-
 config/remote_config.go            | 12 +++++++++---
 config/service_discovery_config.go | 13 +++++++++++--
 8 files changed, 49 insertions(+), 20 deletions(-)

diff --git a/common/constant/key.go b/common/constant/key.go
index 4b867d8..8e5c57d 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -149,6 +149,9 @@ const (
        SingleRegistryConfigPrefix = "dubbo.registry."
        ReferenceConfigPrefix      = "dubbo.reference."
        ServiceConfigPrefix        = "dubbo.service."
+       ConfigBasePrefix           = "dubbo.base."
+       RemotePrefix               = "dubbo.remote."
+       ServiceDiscPrefix          = "dubbo.service-discovery."
        ProtocolConfigPrefix       = "dubbo.protocols."
        ProviderConfigPrefix       = "dubbo.provider."
        ConsumerConfigPrefix       = "dubbo.consumer."
diff --git a/config/base_config.go b/config/base_config.go
index df1686a..71bed2a 100644
--- a/config/base_config.go
+++ b/config/base_config.go
@@ -30,6 +30,7 @@ import (
 
 import (
        "github.com/apache/dubbo-go/common/config"
+       "github.com/apache/dubbo-go/common/constant"
        "github.com/apache/dubbo-go/common/logger"
 )
 
@@ -38,8 +39,8 @@ type BaseConfig struct {
        ConfigCenterConfig *ConfigCenterConfig `yaml:"config_center" 
json:"config_center,omitempty"`
 
        // since 1.5.0 version
-       Remotes              map[string]*RemoteConfig           `yaml:"remote" 
json:"remote,omitempty"`
-       ServiceDiscoveries   map[string]*ServiceDiscoveryConfig 
`yaml:"service_discovery" json:"service_discovery,omitempty"`
+       Remotes              map[string]*RemoteConfig           `yaml:"remote" 
json:"remote,omitempty" property:"remote"`
+       ServiceDiscoveries   map[string]*ServiceDiscoveryConfig 
`yaml:"service_discovery" json:"service_discovery,omitempty" 
property:"service_discovery"`
        MetadataReportConfig *MetadataReportConfig              
`yaml:"metadata_report" json:"metadata_report,omitempty" 
property:"metadata_report"`
 
        // application config
@@ -55,6 +56,10 @@ type BaseConfig struct {
        CacheFile string `yaml:"cache_file" json:"cache_file,omitempty" 
property:"cache_file"`
 }
 
+func (c *BaseConfig) Prefix() string {
+       return constant.ConfigBasePrefix
+}
+
 // nolint
 func (c *BaseConfig) GetServiceDiscoveries(name string) (config 
*ServiceDiscoveryConfig, ok bool) {
        config, ok = c.ServiceDiscoveries[name]
@@ -288,9 +293,7 @@ func initializeStruct(t reflect.Type, v reflect.Value) {
                                f.Set(reflect.MakeChan(ft.Type, 0))
                        }
                case reflect.Struct:
-                       if f.IsNil() {
-                               initializeStruct(ft.Type, f)
-                       }
+                       initializeStruct(ft.Type, f)
                case reflect.Ptr:
                        if f.IsNil() {
                                fv := reflect.New(ft.Type.Elem())
diff --git a/config/config_loader.go b/config/config_loader.go
index 1fd27d5..d6cf08b 100644
--- a/config/config_loader.go
+++ b/config/config_loader.go
@@ -130,6 +130,13 @@ func loadConsumerConfig() {
        if err := configCenterRefreshConsumer(); err != nil {
                logger.Errorf("[consumer config center refresh] %#v", err)
        }
+
+       // start the metadata report if config set
+       if err := startMetadataReport(GetApplicationConfig().MetadataType, 
GetBaseConfig().MetadataReportConfig); err != nil {
+               logger.Errorf("Provider starts metadata report error, and the 
error is {%#v}", err)
+               return
+       }
+
        checkRegistries(consumerConfig.Registries, consumerConfig.Registry)
        for key, ref := range consumerConfig.References {
                if ref.Generic {
@@ -211,6 +218,13 @@ func loadProviderConfig() {
        if err := configCenterRefreshProvider(); err != nil {
                logger.Errorf("[provider config center refresh] %#v", err)
        }
+
+       // start the metadata report if config set
+       if err := startMetadataReport(GetApplicationConfig().MetadataType, 
GetBaseConfig().MetadataReportConfig); err != nil {
+               logger.Errorf("Provider starts metadata report error, and the 
error is {%#v}", err)
+               return
+       }
+
        checkRegistries(providerConfig.Registries, providerConfig.Registry)
 
        // Write the current configuration to cache file.
@@ -344,12 +358,6 @@ func Load() {
        // init the global event dispatcher
        
extension.SetAndInitGlobalDispatcher(GetBaseConfig().EventDispatcherType)
 
-       // start the metadata report if config set
-       if err := startMetadataReport(GetApplicationConfig().MetadataType, 
GetBaseConfig().MetadataReportConfig); err != nil {
-               logger.Errorf("Provider starts metadata report error, and the 
error is {%#v}", err)
-               return
-       }
-
        // reference config
        loadConsumerConfig()
 
diff --git a/config/consumer_config.go b/config/consumer_config.go
index ca88fe3..c50c2a7 100644
--- a/config/consumer_config.go
+++ b/config/consumer_config.go
@@ -43,7 +43,7 @@ const (
 
 // ConsumerConfig is Consumer default configuration
 type ConsumerConfig struct {
-       BaseConfig   `yaml:",inline"`
+       BaseConfig   `yaml:",inline" property:"base"`
        configCenter `yaml:"-"`
        Filter       string `yaml:"filter" json:"filter,omitempty" 
property:"filter"`
        // client
diff --git a/config/metadata_report_config.go b/config/metadata_report_config.go
index 24eba5e..6fb3fd2 100644
--- a/config/metadata_report_config.go
+++ b/config/metadata_report_config.go
@@ -34,8 +34,8 @@ import (
 
 // MethodConfig is method level configuration
 type MetadataReportConfig struct {
-       Protocol  string            `required:"true"  yaml:"protocol"  
json:"protocol,omitempty"`
-       RemoteRef string            `required:"true"  yaml:"remote_ref"  
json:"remote_ref,omitempty"`
+       Protocol  string            `required:"true"  yaml:"protocol"  
json:"protocol,omitempty" property:"protocol"`
+       RemoteRef string            `required:"true"  yaml:"remote_ref"  
json:"remote_ref,omitempty" property:"remote_ref"`
        Params    map[string]string `yaml:"params" json:"params,omitempty" 
property:"params"`
        Group     string            `yaml:"group" json:"group,omitempty" 
property:"group"`
 }
diff --git a/config/provider_config.go b/config/provider_config.go
index 4113aab..ce08ca0 100644
--- a/config/provider_config.go
+++ b/config/provider_config.go
@@ -37,7 +37,7 @@ import (
 
 // ProviderConfig is the default configuration of service provider
 type ProviderConfig struct {
-       BaseConfig     `yaml:",inline"`
+       BaseConfig     `yaml:",inline" property:"base"`
        configCenter   `yaml:"-"`
        Filter         string                     `yaml:"filter" 
json:"filter,omitempty" property:"filter"`
        ProxyFactory   string                     `yaml:"proxy_factory" 
default:"default" json:"proxy_factory,omitempty" property:"proxy_factory"`
diff --git a/config/remote_config.go b/config/remote_config.go
index 61d4dce..98f3baf 100644
--- a/config/remote_config.go
+++ b/config/remote_config.go
@@ -27,6 +27,7 @@ import (
 
 import (
        "github.com/apache/dubbo-go/common"
+       "github.com/apache/dubbo-go/common/constant"
        "github.com/apache/dubbo-go/common/logger"
 )
 
@@ -35,14 +36,19 @@ 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            `yaml:"protocol"  
json:"protocol,omitempty"`
-       Address    string            `yaml:"address" json:"address,omitempty"`
-       TimeoutStr string            `default:"5s" yaml:"timeout" 
json:"timeout,omitempty"`
+       Protocol   string            `yaml:"protocol"  
json:"protocol,omitempty" property:"protocol"`
+       Address    string            `yaml:"address" json:"address,omitempty" 
property:"address"`
+       TimeoutStr string            `default:"5s" yaml:"timeout" 
json:"timeout,omitempty" property:"timeout"`
        Username   string            `yaml:"username" json:"username,omitempty" 
property:"username"`
        Password   string            `yaml:"password" json:"password,omitempty" 
 property:"password"`
        Params     map[string]string `yaml:"params" json:"params,omitempty"`
 }
 
+// Prefix
+func (c *RemoteConfig) Prefix() string {
+       return constant.RemotePrefix
+}
+
 // Timeout return timeout duration.
 // if the configure is invalid, or missing, the default value 5s will be 
returned
 func (rc *RemoteConfig) Timeout() time.Duration {
diff --git a/config/service_discovery_config.go 
b/config/service_discovery_config.go
index d3dc697..da2b75e 100644
--- a/config/service_discovery_config.go
+++ b/config/service_discovery_config.go
@@ -17,14 +17,23 @@
 
 package config
 
+import (
+       "github.com/apache/dubbo-go/common/constant"
+)
+
 // ServiceDiscoveryConfig will be used to create
 type ServiceDiscoveryConfig struct {
        // Protocol indicate which implementation will be used.
        // for example, if the Protocol is nacos, it means that we will use 
nacosServiceDiscovery
-       Protocol string `yaml:"protocol" json:"protocol,omitempty"`
+       Protocol string `yaml:"protocol" json:"protocol,omitempty" 
property:"protocol"`
        // Group, usually you don't need to config this field.
        // you can use this to do some isolation
        Group string `yaml:"group" json:"group,omitempty"`
        // RemoteRef is the reference point to RemoteConfig which will be used 
to create remotes instances.
-       RemoteRef string `yaml:"remote_ref" json:"remote_ref,omitempty"`
+       RemoteRef string `yaml:"remote_ref" json:"remote_ref,omitempty" 
property:"remote_ref"`
+}
+
+// Prefix
+func (c *ServiceDiscoveryConfig) Prefix() string {
+       return constant.ServiceDiscPrefix
 }

Reply via email to