From 16a2e3a52fc879cd636ac8130bbd0c0830b54578 Mon Sep 17 00:00:00 2001 From: Tolga Ozen Date: Tue, 28 Jan 2025 17:22:01 +0300 Subject: [PATCH] refactor(pkg/balancer): Refactor Config struct default value checks --- pkg/balancer/builder.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/balancer/builder.go b/pkg/balancer/builder.go index ef875f5cc..b2ec4d62f 100644 --- a/pkg/balancer/builder.go +++ b/pkg/balancer/builder.go @@ -38,16 +38,16 @@ func (c *Config) ServiceConfigJSON() (string, error) { } // Apply default values for zero fields. - if c.PartitionCount == 0 { + if c.PartitionCount <= 0 { c.PartitionCount = consistent.DefaultPartitionCount } - if c.ReplicationFactor == 0 { + if c.ReplicationFactor <= 0 { c.ReplicationFactor = consistent.DefaultReplicationFactor } - if c.Load == 0 { + if c.Load <= 1.0 { c.Load = consistent.DefaultLoad } - if c.PickerWidth == 0 { + if c.PickerWidth < 1 { c.PickerWidth = consistent.DefaultPickerWidth } @@ -128,16 +128,16 @@ func (b *builder) ParseConfig(rm json.RawMessage) (serviceconfig.LoadBalancingCo ) // Set default values for configuration if not provided. - if cfg.PartitionCount == 0 { + if cfg.PartitionCount <= 0 { cfg.PartitionCount = consistent.DefaultPartitionCount } - if cfg.ReplicationFactor == 0 { + if cfg.ReplicationFactor <= 0 { cfg.ReplicationFactor = consistent.DefaultReplicationFactor } - if cfg.Load == 0 { + if cfg.Load <= 1.0 { cfg.Load = consistent.DefaultLoad } - if cfg.PickerWidth == 0 { + if cfg.PickerWidth < 1 { cfg.PickerWidth = consistent.DefaultPickerWidth }