Skip to content

emitEvents for Go (Gin + GORM): generate a transactional domain-event spine #82

Description

@cultron

Summary

Extend the opt-in emitEvents capability (added for TypeScript in #79 / PR #80) to the Go (Gin + GORM) generator, so that opted-in entities produce a durable domain-event spine written in the same transaction as the state change.

Today emitEvents is parsed and honored only by the TypeScript generator; the Go generator inherits the base no-op (generateDomainEvents returns []), so emitEvents is silently ignored for Go projects.

Reference

#79 / PR #80 is the reference spec. The TypeScript implementation generates a DomainEvent entity (events table), a subscriber writing events transactionally, an app-overridable mapper (event-type taxonomy + payload), a relay (drain/retry; publish() is the app-supplied delivery hook), and a global module wired into the app. Flag resolution is entity.emitEvents ?? <top-level emitEvents> ?? false (global default with per-entity opt-out). Keep the same naming and the same extension-point boundaries.

Language-specific mechanism

The durability lever is ORM-specific. For GORM:

  • Use GORM hooks (AfterCreate/AfterUpdate/AfterDelete) or a registered callback/plugin to write the event row using the hook's *gorm.DB (tx), so the event is inserted within the same transaction as the state change.
  • Map create/update/delete to created/updated/removed.
  • Recursion guard: never emit for the DomainEvent model itself.
  • Scope emission to the opted-in entities only.
  • Provide mapper + relay as overridable extension points (delivery left to the app); a DomainEvent model + events table; relay drains pending rows.

Scope / notes

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions