event

package
v0.0.0-...-f51dab3 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidEnvelope = errors.New("invalid envelope")

ErrInvalidEnvelope indicates the message structure is malformed.

View Source
var ErrNoHandler = errors.New("no handler registered")

ErrNoHandler indicates no registered handler matched the message.

View Source
var ErrSchemaValidation = errors.New("schema validation failed")

ErrSchemaValidation indicates the payload did not match the expected struct.

View Source
var ErrTransientFailure = errors.New("transient failure, please retry")

ErrTransientFailure indicates a transient failure that may succeed if retried.

View Source
var ErrUnprocessableEntity = errors.New("unprocessable entity")

ErrUnprocessableEntity indicates the entity could not be processed.

Functions

func New

func New[T Event](payload T) ([]byte, error)

New creates a publishable JSON payload for the given event. It wraps the event data in the standard envelope with the correct Kind and APIVersion.

func Register

func Register[T Event](r *Router, handler TypedHandler[T])

Register adds a new handler for a specific Kind and APIVersion. T: The struct type you want to receive (e.g. *IngestionJobV1). The router will automatically json.Unmarshal the message into T before calling handler. This function PANICS if a handler for the same Kind and APIVersion is already registered.

Types

type Event

type Event interface {
	Kind() string
	APIVersion() string
}

Event is the interface that all routable messages must implement. It allows the router to infer the Kind and APIVersion from the type itself.

type Router

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

Router acts as a multiplexer for incoming Pub/Sub messages. It automatically handles parsing the envelope, unmarshalling the payload, and dispatching to the correct type-safe handler.

func NewRouter

func NewRouter() *Router

NewRouter creates a new message router.

func (*Router) HandleMessage

func (r *Router) HandleMessage(ctx context.Context, eventID string, data []byte) error

HandleMessage is the single entry point.

type TypedHandler

type TypedHandler[T Event] func(ctx context.Context, eventID string, event T) error

TypedHandler is a function that processes a specific, strongly-typed struct.

Directories

Path Synopsis
batchrefreshtrigger
v1
emailjob
v1
featurediff
v1
refreshsearchcommand
v1
searchconfigurationchanged
v1

Jump to

Keyboard shortcuts

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