Skip to content

Commit 16a2e3a

Browse files
committed
refactor(pkg/balancer): Refactor Config struct default value checks
1 parent 56932e6 commit 16a2e3a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

pkg/balancer/builder.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ func (c *Config) ServiceConfigJSON() (string, error) {
3838
}
3939

4040
// Apply default values for zero fields.
41-
if c.PartitionCount == 0 {
41+
if c.PartitionCount <= 0 {
4242
c.PartitionCount = consistent.DefaultPartitionCount
4343
}
44-
if c.ReplicationFactor == 0 {
44+
if c.ReplicationFactor <= 0 {
4545
c.ReplicationFactor = consistent.DefaultReplicationFactor
4646
}
47-
if c.Load == 0 {
47+
if c.Load <= 1.0 {
4848
c.Load = consistent.DefaultLoad
4949
}
50-
if c.PickerWidth == 0 {
50+
if c.PickerWidth < 1 {
5151
c.PickerWidth = consistent.DefaultPickerWidth
5252
}
5353

@@ -128,16 +128,16 @@ func (b *builder) ParseConfig(rm json.RawMessage) (serviceconfig.LoadBalancingCo
128128
)
129129

130130
// Set default values for configuration if not provided.
131-
if cfg.PartitionCount == 0 {
131+
if cfg.PartitionCount <= 0 {
132132
cfg.PartitionCount = consistent.DefaultPartitionCount
133133
}
134-
if cfg.ReplicationFactor == 0 {
134+
if cfg.ReplicationFactor <= 0 {
135135
cfg.ReplicationFactor = consistent.DefaultReplicationFactor
136136
}
137-
if cfg.Load == 0 {
137+
if cfg.Load <= 1.0 {
138138
cfg.Load = consistent.DefaultLoad
139139
}
140-
if cfg.PickerWidth == 0 {
140+
if cfg.PickerWidth < 1 {
141141
cfg.PickerWidth = consistent.DefaultPickerWidth
142142
}
143143

0 commit comments

Comments
 (0)