Skip to content

Get started with Chronicle for Go

The maintained Go example below registers a typed customer event, appends it and prints its sequence position on success. A live run needs the development kernel started below. Begin with the capability and limits summary, especially before using observers or decision reads. Chronicle.Go handles OAuth, compatibility, registration and transport; you supply the event facts and their source identity.

Use Go 1.26 or newer and Docker. Start the integration kernel matching the contract release:

Terminal window
docker run --rm --name chronicle-go -p 127.0.0.1:35000:35000 cratis/chronicle:19.153.0-development

Wait until curl -skf https://localhost:35000/health returns Healthy; that establishes process health, not feature compatibility. The development image includes MongoDB and a self-signed certificate. Never expose its built-in credentials on a production endpoint.

Go v0.x releases exist; see release policy before selecting a version. The command below asks Go to resolve the latest module. A GitHub release does not by itself establish its module archive contents or kernel compatibility:

Terminal window
go get github.com/cratis/chronicle.go@latest

For the repository source example, use go run ./examples/getting-started from the repository root after providing a compatible endpoint. Do not assume a tagged module contains every API on current main.

This program is maintained as the getting-started example. It uses a bounded operation context, a normal client and explicit cleanup; it is not a runnable WithSkipKeepAlive function/job example. The source ID is event metadata, not a payload property.

package main
import (
"context"
"errors"
"fmt"
"log"
"time"
chronicle "github.com/cratis/chronicle.go"
"github.com/cratis/chronicle.go/events"
)
type CustomerRegistered struct {
Name string `json:"name"`
}
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := appendCustomer(ctx); err != nil {
log.Fatal(err)
}
}
func appendCustomer(ctx context.Context) (err error) {
registry := chronicle.NewRegistry()
if _, err = chronicle.RegisterEvent[CustomerRegistered](registry,
events.WithID("customer-registered")); err != nil {
return err
}
client, err := chronicle.NewClient(chronicle.WithDevelopmentDefaults(),
chronicle.WithRegistry(registry))
if err != nil {
return err
}
defer func() { err = errors.Join(err, client.Close()) }()
store, err := client.EventStore(ctx, "customers")
if err != nil {
return err
}
result, err := store.EventLog().Append(ctx, "customer-42", CustomerRegistered{Name: "Ada"})
if err != nil {
return err
}
if err = result.Err(); err != nil {
return err
}
fmt.Printf("Appended event at position %d\n", *result.Position)
return nil
}

An empty namespace starts at position 0; later runs append at higher sequence-wide positions. Every successful run appends another fact. The program does not retry a failed write: a lost response may hide a committed event.

EventStore connects, ensures the default namespace and waits for event registration before publishing the handle. Registration sent is not observer subscription or catch-up. Close releases the client, including its keep-alive worker. Read short-lived clients and process ownership for skipped-session exclusions and process reuse.

Generated contracts target Chronicle 19.153.0, and the real-kernel tests run against 19.153.0-development. Decision reads have their own exact server/protocol and projection-admission requirements.

Stop your foreground container with Ctrl+C. The example kernel is disposable; configure durable kernel storage separately for real data.