This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/main by this push:
new 3764ba48a fixes #2439, resolve ConsumerConfig nil pointer problem
(#2440)
3764ba48a is described below
commit 3764ba48ad337994ddafb41fae40b82c263ad47c
Author: Scout Wang <[email protected]>
AuthorDate: Wed Oct 11 16:09:43 2023 +0800
fixes #2439, resolve ConsumerConfig nil pointer problem (#2440)
---
config/reference_config.go | 35 ++++++++++++++++++-----------------
config/reference_config_test.go | 7 +++++++
2 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/config/reference_config.go b/config/reference_config.go
index 64d7c53a3..e38372ec9 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -101,30 +101,31 @@ func (rc *ReferenceConfig) Init(root *RootConfig) error {
rc.Version = root.Application.Version
}
}
- if rc.Filter == "" {
- rc.Filter = root.Consumer.Filter
+ rc.RegistryIDs = translateIds(rc.RegistryIDs)
+ if root.Consumer != nil {
+ if rc.Filter == "" {
+ rc.Filter = root.Consumer.Filter
+ }
+ if len(rc.RegistryIDs) <= 0 {
+ rc.RegistryIDs = root.Consumer.RegistryIDs
+ }
+ if rc.Protocol == "" {
+ rc.Protocol = root.Consumer.Protocol
+ }
+ if rc.TracingKey == "" {
+ rc.TracingKey = root.Consumer.TracingKey
+ }
+ if rc.Check == nil {
+ rc.Check = &root.Consumer.Check
+ }
}
if rc.Cluster == "" {
rc.Cluster = "failover"
}
- rc.RegistryIDs = translateIds(rc.RegistryIDs)
- if len(rc.RegistryIDs) <= 0 {
- rc.RegistryIDs = root.Consumer.RegistryIDs
- }
-
- if rc.Protocol == "" {
- rc.Protocol = root.Consumer.Protocol
- }
-
- if rc.TracingKey == "" {
- rc.TracingKey = root.Consumer.TracingKey
- }
if root.Metric.Enable != nil {
rc.metricsEnable = *root.Metric.Enable
}
- if rc.Check == nil {
- rc.Check = &root.Consumer.Check
- }
+
return verify(rc)
}
diff --git a/config/reference_config_test.go b/config/reference_config_test.go
index 8e0d1e37f..13a5ed23d 100644
--- a/config/reference_config_test.go
+++ b/config/reference_config_test.go
@@ -460,3 +460,10 @@ func TestNewReferenceConfigBuilder(t *testing.T) {
invoker := config.GetInvoker()
assert.Nil(t, invoker)
}
+
+func TestReferenceConfigInitWithoutConsumerConfig(t *testing.T) {
+ testRootConfig := NewRootConfigBuilder().Build()
+ testRootConfig.Consumer = nil
+ err := NewReferenceConfigBuilder().Build().Init(testRootConfig)
+ assert.Nil(t, err)
+}