Skip to content

Commit

Permalink
refactor(pkg/balancer): Refactor Config struct default value checks
Browse files Browse the repository at this point in the history
  • Loading branch information
tolgaOzen committed Jan 28, 2025
1 parent 56932e6 commit 16a2e3a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/balancer/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 16a2e3a

Please sign in to comment.