diff --git a/config/config.go b/config/config.go index eef0a74f..2d82964a 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,7 @@ package config import ( + "cmp" "fmt" "os" "strings" @@ -24,11 +25,7 @@ func (k *Kafka) BootstrapAddresses() []string { } func (k *Kafka) GetPublishSize() uint { - if k.PublishSize == 0 { - return constants.DefaultPublishSize - } - - return k.PublishSize + return cmp.Or(k.PublishSize, constants.DefaultPublishSize) } func (k *Kafka) Validate() error { @@ -195,15 +192,11 @@ func ReadConfig(fp string) (*Settings, error) { return nil, fmt.Errorf("failed to unmarshal config file: %w", err) } - if settings.Source == "" { - // By default, if you don't pass in a source -- it will be dynamodb for backwards compatibility - settings.Source = SourceDynamo - } + // By default, if you don't pass in a source -- it will be dynamodb for backwards compatibility + settings.Source = cmp.Or(settings.Source, SourceDynamo) - if settings.Destination == "" { - // By default, if you don't pass in a destination -- it will be Kafka for backwards compatibility - settings.Destination = DestinationKafka - } + // By default, if you don't pass in a destination -- it will be Kafka for backwards compatibility + settings.Destination = cmp.Or(settings.Destination, DestinationKafka) if err = settings.Validate(); err != nil { return nil, fmt.Errorf("failed to validate config file: %w", err) diff --git a/config/mongodb.go b/config/mongodb.go index b5470e3c..eacd109d 100644 --- a/config/mongodb.go +++ b/config/mongodb.go @@ -1,7 +1,9 @@ package config import ( + "cmp" "fmt" + "github.com/artie-labs/reader/constants" "github.com/artie-labs/transfer/lib/stringutil" ) @@ -26,11 +28,7 @@ func (c Collection) TopicSuffix(db string) string { } func (c Collection) GetBatchSize() int32 { - if c.BatchSize == 0 { - return constants.DefaultBatchSize - } - - return c.BatchSize + return cmp.Or(c.BatchSize, constants.DefaultBatchSize) } func (m MongoDB) Validate() error {