Skip to content

Commit

Permalink
Replace array.Empty with stringutil.Empty (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed May 18, 2024
1 parent fa56bc1 commit ed024af
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 32 deletions.
12 changes: 0 additions & 12 deletions lib/array/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,3 @@ func InterfaceToArrayString(val any, recastAsArray bool) ([]string, error) {

return vals, nil
}

// Empty will iterate over a list, if one of the item in the list is empty, it will return true
// This is useful to check the presence of a setting.
func Empty(list []string) bool {
for _, v := range list {
if empty := v == ""; empty {
return true
}
}

return false
}
13 changes: 0 additions & 13 deletions lib/array/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,3 @@ func TestToArrayString(t *testing.T) {
}

}

func TestNotEmpty(t *testing.T) {
notEmptyList := []string{
"aaa",
"foo",
"bar",
}

assert.False(t, Empty(notEmptyList))

notEmptyList = append(notEmptyList, "")
assert.True(t, Empty(notEmptyList))
}
5 changes: 2 additions & 3 deletions lib/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"gopkg.in/yaml.v3"

"github.com/artie-labs/transfer/lib/array"
"github.com/artie-labs/transfer/lib/config/constants"
"github.com/artie-labs/transfer/lib/kafkalib"
"github.com/artie-labs/transfer/lib/numbers"
Expand Down Expand Up @@ -279,15 +278,15 @@ func (c Config) Validate() error {
}

// Username and password are not required (if it's within the same VPC or connecting locally
if array.Empty([]string{c.Kafka.GroupID, c.Kafka.BootstrapServer}) {
if stringutil.Empty(c.Kafka.GroupID, c.Kafka.BootstrapServer) {
return fmt.Errorf("kafka group or bootstrap server is empty")
}
case constants.PubSub:
if c.Pubsub == nil {
return fmt.Errorf("pubsub config is nil")
}

if array.Empty([]string{c.Pubsub.ProjectID, c.Pubsub.PathToCredentials}) {
if stringutil.Empty(c.Pubsub.ProjectID, c.Pubsub.PathToCredentials) {
return fmt.Errorf("pubsub projectID or pathToCredentials is empty")
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/kafkalib/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"slices"
"strings"

"github.com/artie-labs/transfer/lib/array"
"github.com/artie-labs/transfer/lib/kafkalib/partition"
"github.com/artie-labs/transfer/lib/stringutil"
)

type DatabaseSchemaPair struct {
Expand Down Expand Up @@ -91,7 +91,7 @@ func (t TopicConfig) String() string {

func (t TopicConfig) Validate() error {
// IdempotentKey is optional.
empty := array.Empty([]string{t.Database, t.Schema, t.Topic, t.CDCFormat})
empty := stringutil.Empty(t.Database, t.Schema, t.Topic, t.CDCFormat)
if empty {
return fmt.Errorf("database, schema, topic or cdc format is empty")
}
Expand Down
3 changes: 1 addition & 2 deletions models/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"time"

"github.com/artie-labs/transfer/lib/array"
"github.com/artie-labs/transfer/lib/artie"
"github.com/artie-labs/transfer/lib/cdc"
"github.com/artie-labs/transfer/lib/config"
Expand Down Expand Up @@ -82,7 +81,7 @@ func ToMemoryEvent(event cdc.Event, pkMap map[string]any, tc *kafkalib.TopicConf

func (e *Event) IsValid() bool {
// Does it have a PK or table set?
if array.Empty([]string{e.Table}) {
if stringutil.Empty(e.Table) {
return false
}

Expand Down

0 comments on commit ed024af

Please sign in to comment.