Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ type AggregateHandler interface {
ApplyChange(event Event)
ApplyChangeHelper(aggregate AggregateHandler, event Event, commit bool)
HandleCommand(Command) error
Uncommited() []Event
ClearUncommited()
Uncommitted() []Event
ClearUncommitted()
IncrementVersion()
GetID() string
}

// Uncommited return the events to be saved
func (b *BaseAggregate) Uncommited() []Event {
// Uncommitted return the events to be saved
func (b *BaseAggregate) Uncommitted() []Event {
return b.Changes
}

// ClearUncommited the events
func (b *BaseAggregate) ClearUncommited() {
// ClearUncommitted the events
func (b *BaseAggregate) ClearUncommitted() {
b.Changes = []Event{}
}

Expand Down
10 changes: 5 additions & 5 deletions aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ type MockAggregate struct {
BaseAggregate
}

func TestBaseAggregateUncommited(t *testing.T) {
func TestBaseAggregateUncommitted(t *testing.T) {
var mock MockAggregate
var event Event

length := len(mock.Uncommited())
length := len(mock.Uncommitted())
if length != 0 {
t.Error("expected 0, got", length)
}

mock.Changes = append(mock.Changes, event)

length = len(mock.Uncommited())
length = len(mock.Uncommitted())
if length == 0 {
t.Error("expected 0, got", length)
}

mock.ClearUncommited()
length = len(mock.Uncommited())
mock.ClearUncommitted()
length = len(mock.Uncommitted())
if length != 0 {
t.Error("expected 0, got", length)
}
Expand Down
2 changes: 1 addition & 1 deletion command.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package eventhus

// Command contains the methods to retreive basic info about it
// Command contains the methods to retrieve basic info about it
type Command interface {
GetType() string
GetAggregateID() string
Expand Down
4 changes: 2 additions & 2 deletions commandhandler/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// ErrInvalidID missing initial event
var ErrInvalidID = errors.New("Invalid ID, initial event missign")
var ErrInvalidID = errors.New("Invalid ID, initial event missing")

// Handler contains the info to manage commands
type Handler struct {
Expand Down Expand Up @@ -44,7 +44,7 @@ func (h *Handler) Handle(command eventhus.Command) error {
return err
}

// if not contain a valid ID, the initial event (some like createAggreagate event) is missing
// if not contain a valid ID, the initial event (some like createAggregate event) is missing
if aggregate.GetID() == "" {
return ErrInvalidID
}
Expand Down
4 changes: 2 additions & 2 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ type EventTypeRegister interface {
Events() []string
}

// EventType implements the EventyTypeRegister interface
// EventType implements the EventTypeRegister interface
type EventType struct {
sync.RWMutex
}

// NewEventRegister gets a EventyTypeRegister interface
// NewEventRegister gets a EventTypeRegister interface
func NewEventRegister() EventTypeRegister {
return &EventType{}
}
Expand Down
2 changes: 1 addition & 1 deletion eventbus/eventbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type MultiPublisherError struct {

// Error will produce an error message out of all errors.
func (e MultiPublisherError) Error() string {
o := "A few errors occured:"
o := "A few errors occurred:"

for i, err := range e.Errors {
o = fmt.Sprintf("%s\n\t%d) %s", o, i+1, err)
Expand Down
2 changes: 1 addition & 1 deletion eventbus/eventbus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func Test_MultiPublisherError_String(t *testing.T) {
sut.Add(errors.New("testing"))
sut.Add(errors.New("testing"))

e := `A few errors occured:
e := `A few errors occurred:
1) testing
2) testing
3) testing`
Expand Down
2 changes: 1 addition & 1 deletion eventstore/mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (c *Client) Load(aggregateID string) ([]eventhus.Event, error) {
return events, err
}

// Set conrcete event and zero out the decoded event.
// Set concrete event and zero out the decoded event.
dbEvent.data = dataType
dbEvent.RawData = bson.Raw{}

Expand Down
12 changes: 6 additions & 6 deletions examples/bank/cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ func main() {
commandBus.HandleCommand(deposit)
glog.Infof("account %s - deposit performed", uuid)

//3) Perform a withdrawl
//3) Perform a withdrawal
time.Sleep(time.Millisecond * 100)
withdrawl := bank.PerformWithdrawal{
withdrawal := bank.PerformWithdrawal{
Amount: 249,
}

withdrawl.AggregateID = uuid
withdrawl.Version = 2
withdrawal.AggregateID = uuid
withdrawal.Version = 2

commandBus.HandleCommand(withdrawl)
glog.Infof("account %s - withdrawl performed", uuid)
commandBus.HandleCommand(withdrawal)
glog.Infof("account %s - withdrawal performed", uuid)
}()
}
<-end
Expand Down
2 changes: 1 addition & 1 deletion examples/bank/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ type OwnerChanged struct {

//WithdrawalPerformed event
type WithdrawalPerformed struct {
Amount int `json:"ammount"`
Amount int `json:"amount"`
}
6 changes: 3 additions & 3 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ func (r *Repository) Load(aggregate AggregateHandler, ID string) error {

// Save the events and publish it to eventbus
func (r *Repository) Save(aggregate AggregateHandler, version int) error {
return r.eventStore.Save(aggregate.Uncommited(), version)
return r.eventStore.Save(aggregate.Uncommitted(), version)
}

// PublishEvents to an eventBus
func (r *Repository) PublishEvents(aggregate AggregateHandler, bucket, subset string) error {
var err error

for _, event := range aggregate.Uncommited() {
for _, event := range aggregate.Uncommitted() {
if err = r.eventBus.Publish(event, bucket, subset); err != nil {
return err
}
Expand All @@ -49,5 +49,5 @@ func (r *Repository) PublishEvents(aggregate AggregateHandler, bucket, subset st

// SafeSave the events without check the version
func (r *Repository) SafeSave(aggregate AggregateHandler, version int) error {
return r.eventStore.SafeSave(aggregate.Uncommited(), version)
return r.eventStore.SafeSave(aggregate.Uncommitted(), version)
}
2 changes: 1 addition & 1 deletion utils/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/oklog/ulid"
)

// UUID retunrs an unique id basend on ulid algorithm
// UUID returns an unique id based on ULID algorithm
func UUID() (string, error) {
t := time.Unix(1000000, 0)
entropy := make([]byte, 48)
Expand Down