Chronicle – idiomatic, type safe event sourcing framework for Go

https://news.ycombinator.com/rss Hits: 4
Summary

Chronicle A pragmatic and type-safe toolkit for modern event sourcing in Go. Want to hire me? Quickstart Warning I recommend going through the quickstart, since all examples use the Account struct used below from the account package. Install the library go get github.com/DeluxeOwl/chronicle # for debugging go get github.com/sanity-io/litter Define your aggregate and embed aggregate.Base . This embedded struct handles the versioning of the aggregate for you. We'll use a classic yet very simplified bank account example: package account import ( "errors" "fmt" "time" "github.com/DeluxeOwl/chronicle/aggregate" "github.com/DeluxeOwl/chronicle/event" ) type Account struct { aggregate. Base } Declare a type for the aggregate's ID. This ID type MUST implement fmt.Stringer . You also need to add an ID() method to your aggregate that returns this ID. type AccountID string func ( a AccountID ) String () string { return string ( a ) } type Account struct { aggregate. Base id AccountID } func ( a * Account ) ID () AccountID { return a . id } Declare the event type for your aggregate using a sum type (we're also using the go-check-sumtype linter that comes with golangci-lint) for type safety: //sumtype:decl type AccountEvent interface { event. Any isAccountEvent () } Now declare the events that are relevant for your business domain. The events MUST be side effect free (no i/o). The event methods ( EventName , isAccountEvent ) MUST have pointer receivers: // We say an account is "opened", not "created" type accountOpened struct { ID AccountID `json:"id"` OpenedAt time. Time `json:"openedAt"` HolderName string `json:"holderName"` } func ( * accountOpened ) EventName () string { return "account/opened" } func ( * accountOpened ) isAccountEvent () {} By default, events are serialized to JSON (this can be changed when you configure the repository). To satisfy the event.Any interface (embedded in AccountEvent ), you must add an EventName() string method to each event. Let's implement t...

First seen: 2025-09-01 12:47

Last seen: 2025-09-01 15:48