Skip to content

Commit 6c66819

Browse files
Minor code improvements
Combining some var declarations, fixing a type, etc.
1 parent 6444341 commit 6c66819

File tree

8 files changed

+18
-33
lines changed

8 files changed

+18
-33
lines changed

aggregate/aggregate_type.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import (
77
"github.com/hellofresh/goengine"
88
)
99

10-
var (
11-
// ErrInitiatorMustReturnRoot occurs when a aggregate.Initiator did not return a pointer
12-
ErrInitiatorMustReturnRoot = errors.New("goengine: the aggregate.Initiator must return a pointer to the aggregate.Root")
13-
)
10+
// ErrInitiatorMustReturnRoot occurs when a aggregate.Initiator did not return a pointer
11+
var ErrInitiatorMustReturnRoot = errors.New("goengine: the aggregate.Initiator must return a pointer to the aggregate.Root")
1412

1513
type (
1614
// Initiator creates a new empty instance of a aggregate.Root

aggregate/repository.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ var (
2626
ErrEmptyEventStream = errors.New("goengine: unsupported empty event stream")
2727
)
2828

29-
type (
30-
// Repository a repository to save and load aggregate.Root's of a specific type
31-
Repository struct {
32-
aggregateType *Type
33-
eventStore goengine.EventStore
34-
streamName goengine.StreamName
35-
}
36-
)
29+
// Repository a repository to save and load aggregate.Root's of a specific type
30+
type Repository struct {
31+
aggregateType *Type
32+
eventStore goengine.EventStore
33+
streamName goengine.StreamName
34+
}
3735

3836
// NewRepository instantiates a new AggregateRepository
3937
func NewRepository(

driver/inmemory/internal/generate_matcher/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import (
2121
"github.com/hellofresh/goengine/metadata"
2222
)
2323
24-
var (
25-
ErrUnsupportedType = errors.New("the value is not a scalar type")
26-
)
24+
var ErrUnsupportedType = errors.New("the value is not a scalar type")
2725
2826
func asScalar(value interface{}) (interface{}, error) {
2927
switch value.(type) {

driver/inmemory/matcher_gen.go

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

driver/sql/postgres/advisory_lock_aggregate_projection_storage.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (a *AdvisoryLockAggregateProjectionStorage) PersistFailure(conn driverSQL.E
120120
}
121121

122122
// Acquire returns a driverSQL.ProjectorTransaction and the position of the projection within the event stream when a
123-
// lock is acquire for the specified aggregate_id. Otherwise an error is returned indicating why the lock could not be acquired.
123+
// lock is acquired for the specified aggregate_id. Otherwise an error is returned indicating why the lock could not be acquired.
124124
func (a *AdvisoryLockAggregateProjectionStorage) Acquire(
125125
ctx context.Context,
126126
conn *sql.Conn,
@@ -135,10 +135,8 @@ func (a *AdvisoryLockAggregateProjectionStorage) Acquire(
135135
res := conn.QueryRowContext(ctx, a.queryAcquireLock, aggregateID, notification.No)
136136

137137
var (
138-
acquiredLock bool
139-
locked bool
140-
failed bool
141-
projectionState driverSQL.ProjectionRawState
138+
acquiredLock, locked, failed bool
139+
projectionState driverSQL.ProjectionRawState
142140
)
143141
if err := res.Scan(&acquiredLock, &locked, &failed, &projectionState.Position, &projectionState.ProjectionState); err != nil {
144142
// No rows are returned when the projector is already at the notification position

driver/sql/postgres/advisory_lock_aggregate_projection_storage_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import (
77
"errors"
88
"testing"
99

10-
"github.com/stretchr/testify/assert"
11-
1210
"github.com/golang/mock/gomock"
1311
"github.com/hellofresh/goengine"
1412
driverSQL "github.com/hellofresh/goengine/driver/sql"
1513
"github.com/hellofresh/goengine/driver/sql/postgres"
1614
"github.com/hellofresh/goengine/mocks/driver/sql"
15+
"github.com/stretchr/testify/assert"
1716
"github.com/stretchr/testify/require"
1817
)
1918

driver/sql/postgres/advisory_lock_stream_projection_storage.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,8 @@ func (s *AdvisoryLockStreamProjectionStorage) Acquire(
121121
}
122122

123123
var (
124-
acquiredLock bool
125-
locked bool
126-
projectionState driverSQL.ProjectionRawState
124+
acquiredLock, locked bool
125+
projectionState driverSQL.ProjectionRawState
127126
)
128127
if err := res.Scan(&acquiredLock, &locked, &projectionState.Position, &projectionState.ProjectionState); err != nil {
129128
// No rows are returned when the projector is already at the notification position

driver/sql/projector_notification.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,8 @@ func (s *notificationProjector) projectStream(
150150
ctx context.Context,
151151
tx ProjectorTransaction,
152152
stream *eventStreamHandlerIterator,
153-
) error {
154-
var (
155-
err error
156-
state ProjectionState
157-
)
153+
) (err error) {
154+
var state ProjectionState
158155
for stream.Next() {
159156
// Check if the context is expired
160157
select {

0 commit comments

Comments
 (0)