modernice / goes

goes is an event-sourcing framework for Go.
https://goes.modernice.dev
Apache License 2.0
134 stars 12 forks source link

Built-in commands #10

Closed bounoable closed 3 years ago

bounoable commented 3 years ago

Add built-in commands for common actions:

Delete aggregate

command.DeleteAggregate() should delete an aggregate by deleting its events:

package example

func delete(aggregateName string, aggregateID uuid.UUID, bus command.Bus) {
    cmd := command.DeleteAggregate(aggregateName, aggregateID)
    bus.Dispatch(context.TODO(), cmd)
}

Handle built-in commands

package main

import "github.com/modernice/goes/command"

func main() {
    var ctx context.Context
    var bus command.Bus

    errs, err := command.HandleBuiltin(ctx, bus)
    if err != nil {
        log.Fatalf("handle built-in goes commands: %w", err)
    }

    for err := range errs {
        log.Println(fmt.Errorf("handle command: %w", err)
    }
}