|
| 1 | +// Package event is the core of goes. It defines and implements a generic event |
| 2 | +// system that is used as the building block for all the other components |
| 3 | +// provided by goes. |
| 4 | +// |
| 5 | +// The core type of this package is the Event interface. An event is either an |
| 6 | +// application event or an aggregate event, depending on the provided data. |
| 7 | +// Read the documentation of the Event interface for more information. |
| 8 | +// |
| 9 | +// To create an event, pass at least the name of the event and some arbitrary |
| 10 | +// event data to the New function: |
| 11 | +// |
| 12 | +// evt := event.New("foo", 3) |
| 13 | +// // evt.ID() == uuid.UUID{...} |
| 14 | +// // evt.Name() == "foo" |
| 15 | +// // evt.Time() == time.Now() |
| 16 | +// // evt.Data() == 3 |
| 17 | +// |
| 18 | +// Events can be published to subscribers over an event bus: |
| 19 | +// |
| 20 | +// var bus event.Bus |
| 21 | +// evt := event.New("foo", 3) |
| 22 | +// err := bus.Publish(context.TODO(), evt) |
| 23 | +// |
| 24 | +// Events can also be subscribed to using an event bus: |
| 25 | +// |
| 26 | +// // Subscribe to "foo", "bar", and "baz" events. |
| 27 | +// events, errs, err := bus.Subscribe(context.TODO(), "foo", "bar", "baz") |
| 28 | +// |
| 29 | +// Events can be inserted into and queried from an event store: |
| 30 | +// |
| 31 | +// var store event.Store |
| 32 | +// evt := event.New("foo", 3) |
| 33 | +// err := store.Insert(context.TODO(), evt) |
| 34 | +// |
| 35 | +// events, errs, err := store.Query(context.TODO(), query.New( |
| 36 | +// query.Name("foo"), // query "foo" events |
| 37 | +// query.SortByTime(), // sort events by time |
| 38 | +// )) |
| 39 | +// |
| 40 | +// Depending on the used event store and/or event bus implementations, it may be |
| 41 | +// required to pass an Encoding for your event data to the store/bus. Example |
| 42 | +// using encoding/gob for encoding of event data: |
| 43 | +// |
| 44 | +// enc := codec.Gob(event.NewRegistry()) |
| 45 | +// codec.GobRegister[int](enc, "foo") // register "foo" as an int |
| 46 | +// codec.GobRegister[string](enc, "bar") // register "bar" as a string |
| 47 | +// codec.GobRegister[struct{Foo string}](enc, "baz") // register "baz" as a struct{Foo string} |
| 48 | +// store := mongo.NewEventStore(enc) |
| 49 | +package event |
0 commit comments