events

package
v0.36.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PublishLicenseEvent

func PublishLicenseEvent(pub *Publisher) func(c *gin.Context, id string, revision int, action string, data vo.LicenseVO)

PublishLicenseEvent publishes a license entity event.

func PublishPersonEvent

func PublishPersonEvent(pub *Publisher) func(c *gin.Context, id string, revision int, action string, data vo.PersonVO)

PublishPersonEvent publishes a person entity event.

func PublishPublisherEvent

func PublishPublisherEvent(pub *Publisher) func(c *gin.Context, id string, revision int, action string, data vo.PublisherVO)

PublishPublisherEvent publishes a publisher entity event.

func PublishStudioEvent

func PublishStudioEvent(pub *Publisher) func(c *gin.Context, id string, revision int, action string, data vo.StudioVO)

PublishStudioEvent publishes a studio entity event.

Types

type Consumer added in v0.29.0

type Consumer struct {
	// contains filtered or unexported fields
}

Consumer binds catalog-api's durable pull consumer on the game-systems events stream and dispatches system.updated events to a handler.

func NewConsumer added in v0.29.0

func NewConsumer(ctx context.Context) (*Consumer, error)

NewConsumer builds a Consumer from the environment (same NATS_URL / NATS_CREDS / NATS_USER+NATS_PASSWORD scheme as the publisher). Returns (nil, nil) when NATS_URL is unset so the caller treats sync as disabled rather than a startup error.

func (*Consumer) Start added in v0.29.0

func (c *Consumer) Start(ctx context.Context, handle SystemUpdateHandler) error

Start binds the durable (declared as a NACK CRD in sweetrpg/infrastructure; created here as a fallback for local runs without NACK) and begins delivering events to handle in the background. It returns once the subscription is established.

func (*Consumer) Stop added in v0.29.0

func (c *Consumer) Stop()

Stop halts delivery and closes the connection.

type Envelope

type Envelope struct {
	EventID    string          `json:"event_id"`
	OccurredAt string          `json:"occurred_at"`
	Source     string          `json:"source"`
	EntityType string          `json:"entity_type"`
	EntityID   string          `json:"entity_id"`
	Action     string          `json:"action"`
	Revision   int             `json:"revision"`
	Data       json.RawMessage `json:"data"`
}

Envelope is the JSON event payload published to NATS JetStream. Fields: event_id (UUID string), occurred_at (RFC3339), source ("catalog-api"), entity_type, entity_id, action, revision (entity's post-change version, 0 for delete), data (object; for volume.updated include at least the current title; may be empty for delete).

func NewEnvelope

func NewEnvelope(eventID, entityType, entityID, action string, revision int, data interface{}) (*Envelope, error)

NewEnvelope creates a new event envelope with all required fields. eventID should be a UUID string, occurredAt is RFC3339 formatted, revision is the entity's post-change version (0 for delete), and data is arbitrary JSON (may be null).

type Publisher

type Publisher struct {
	// contains filtered or unexported fields
}

Publisher publishes entity-change events to NATS JetStream.

func NewPublisher

func NewPublisher(ctx context.Context) (*Publisher, error)

NewPublisher creates a new NATS JetStream publisher from environment configuration. NATS_URL: NATS server URL (e.g., "nats://localhost:4222") NATS_CREDS: path to credentials file (optional, empty/unset for no-auth) PUBLISH_TIMEOUT_MS: milliseconds to wait for publish (default 3000)

func (*Publisher) Close

func (p *Publisher) Close()

Close closes the NATS connection.

func (*Publisher) PublishEntityCreated

func (p *Publisher) PublishEntityCreated(ctx context.Context, entityType, entityID string, revision int, data interface{})

PublishEntityCreated publishes a created event for an entity. data is the entity's current state.

func (*Publisher) PublishEntityDeleted

func (p *Publisher) PublishEntityDeleted(ctx context.Context, entityType, entityID string)

PublishEntityDeleted publishes a deleted event for an entity. revision is 0 for delete, data may be empty.

func (*Publisher) PublishEntityUpdated

func (p *Publisher) PublishEntityUpdated(ctx context.Context, entityType, entityID string, revision int, data interface{})

PublishEntityUpdated publishes an updated event for an entity. data is the entity's current state (for volume.updated must include title).

type SystemUpdateHandler added in v0.29.0

type SystemUpdateHandler func(ctx context.Context, systemID, title string) error

SystemUpdateHandler applies one gamesystems.events.system.updated event. Returning an error Naks the message so JetStream redelivers it; the handler MUST be idempotent.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL