Skip to content

Commit

Permalink
fixes #2439, resolve ConsumerConfig nil pointer problem (#2440)
Browse files Browse the repository at this point in the history
  • Loading branch information
DMwangnima authored Oct 11, 2023
1 parent debe37d commit 3764ba4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
35 changes: 18 additions & 17 deletions config/reference_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
7 changes: 7 additions & 0 deletions config/reference_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 3764ba4

Please sign in to comment.