Skip to content

Make Go event APIs typed by default#24

Merged
pirate merged 2 commits into
mainfrom
go-typed-event-api
May 14, 2026
Merged

Make Go event APIs typed by default#24
pirate merged 2 commits into
mainfrom
go-typed-event-api

Conversation

@pirate
Copy link
Copy Markdown
Member

@pirate pirate commented May 13, 2026

Summary

  • make Go EventBus.On, Emit, Find, and Filter the typed/default APIs
  • add explicit *EventName variants for raw string and wildcard event-name flows
  • replace old typed helper names in Go tests and docs, including docs snippets for event-name emission and lookup

Validation

  • go test -count=1 ./... from abxbus-go
  • git diff --check
  • attempted pnpm dlx mintlify@latest broken-links, but Mintlify refused to run on Node 25.9.0 because it requires an LTS Node version

Summary by cubic

Makes the Go event APIs typed by default for safer handlers and clearer ergonomics. EventBus.On, Find, and Filter now prefer typed payloads and predicates; string and wildcard flows use explicit *EventName methods. Adds runtime schema validation for typed payloads and results.

  • Migration
    • Use On for typed handlers: func(TPayload), func(TPayload) (TResult, error), and context variants also work. On can infer the event name from the handler’s first param type via bus.On(handler). On panics if given "" or "*".
    • Use OnEventName for raw string names or "*" wildcard handlers that receive *BaseEvent.
    • Use Find/Filter in typed form: pass a typed event (zero value or instance) and optional where func(TPayload) bool. For string/wildcard, use FindEventName/FilterEventName.
    • Emit typed events with bus.Emit(MyEvent{...}); for raw names use EmitEventName/EmitEventNameWithContext. From inside handlers, prefer event.Emit(MyChildEvent{...}) or event.EmitEventName(...) for raw names.
    • Replace old helpers: OnTyped[...], NewBaseEventWithResult[...], and similar are superseded by NewEvent[T](name, payload, ResultType[R]()), MustNewEvent, and Event(payload).
    • Typed handlers now validate payloads/results at runtime; schema mismatches raise EventHandlerPayloadSchemaError/EventHandlerResultSchemaError.
    • JSONL bridge: use bridge.OnEventName for string/wildcard; bridge.On supports typed handlers.

Written for commit 5bcd08a. Summary will update on new commits.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@pirate pirate merged commit fdff597 into main May 14, 2026
117 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant