Skip to content

Commit 5715f11

Browse files
committed
refactor: removed unnecessary pointers to slices
1 parent a9626b3 commit 5715f11

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

mongodb/collection.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type (
1111
// Collection represents a MongoDB collection
1212
Collection struct {
1313
name string
14-
Indexes *[]*mongo.IndexModel
14+
Indexes []*mongo.IndexModel
1515
}
1616
)
1717

@@ -27,7 +27,7 @@ type (
2727
// - *Collection: the new collection
2828
func NewCollection(
2929
name string,
30-
indexes *[]*mongo.IndexModel,
30+
indexes []*mongo.IndexModel,
3131
) *Collection {
3232
return &Collection{
3333
name,
@@ -64,20 +64,22 @@ func (c Collection) CreateCollection(database *mongo.Database) (
6464
//
6565
// - error: if there was an error creating the indexes
6666
func (c Collection) createIndexes(collection *mongo.Collection) (err error) {
67-
if c.Indexes != nil {
68-
for _, index := range *c.Indexes {
69-
// Check if the index is nil
70-
if index == nil {
71-
continue
72-
}
67+
if c.Indexes == nil {
68+
return nil
69+
}
70+
71+
for _, index := range c.Indexes {
72+
// Check if the index is nil
73+
if index == nil {
74+
continue
75+
}
7376

74-
// Create the index
75-
_, err = collection.Indexes().CreateOne(
76-
context.Background(), *index,
77-
)
78-
if err != nil {
79-
return fmt.Errorf(ErrFailedToCreateIndex, *index, err)
80-
}
77+
// Create the index
78+
_, err = collection.Indexes().CreateOne(
79+
context.Background(), *index,
80+
)
81+
if err != nil {
82+
return fmt.Errorf(ErrFailedToCreateIndex, *index, err)
8183
}
8284
}
8385
return nil

sql/queries.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import (
1515
//
1616
// Returns:
1717
//
18-
// *[]error: A pointer to a slice of errors, or nil if no errors occurred
18+
// []error: A slice of errors, or nil if no errors occurred
1919
func RunQueriesConcurrently(
2020
db *sql.DB,
2121
queries ...func(db *sql.DB) error,
22-
) *[]error {
22+
) []error {
2323
// Create a wait group
2424
var wg sync.WaitGroup
2525
wg.Add(len(queries))
@@ -55,7 +55,7 @@ func RunQueriesConcurrently(
5555
return nil
5656
}
5757

58-
return &errors
58+
return errors
5959
}
6060

6161
// RunQueriesConcurrentlyWithCancel runs multiple queries concurrently with a cancel context
@@ -67,11 +67,11 @@ func RunQueriesConcurrently(
6767
//
6868
// Returns:
6969
//
70-
// *[]error: A pointer to a slice of errors, or nil if no errors occurred
70+
// []error: A slice of errors, or nil if no errors occurred
7171
func RunQueriesConcurrentlyWithCancel(
7272
db *sql.DB,
7373
queries ...func(db *sql.DB, ctx context.Context) error,
74-
) *[]error {
74+
) []error {
7575
// Create a context with a cancellation function
7676
ctx, cancel := context.WithCancel(context.Background())
7777
defer cancel()
@@ -114,5 +114,5 @@ func RunQueriesConcurrentlyWithCancel(
114114
return nil
115115
}
116116

117-
return &errors
117+
return errors
118118
}

0 commit comments

Comments
 (0)