Skip to content

Commit

Permalink
Merge branch 'master' into nv/cmp-or
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie authored May 18, 2024
2 parents 45d58ab + 048e253 commit b924d93
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
19 changes: 6 additions & 13 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"cmp"
"fmt"
"os"
"strings"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions config/mongodb.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package config

import (
"cmp"
"fmt"

"github.com/artie-labs/reader/constants"
"github.com/artie-labs/transfer/lib/stringutil"
)
Expand All @@ -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 {
Expand Down

0 comments on commit b924d93

Please sign in to comment.