mediator

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Name    string
	Payload interface{}
}

Event represents a generic event in the system

type EventHandler

type EventHandler func(ctx context.Context, event Event) error

EventHandler is a function type that handles events

type EventStore

type EventStore interface {
	// StoreEvent stores an event
	StoreEvent(ctx context.Context, event Event) error

	// GetEvents retrieves events by event name
	GetEvents(ctx context.Context, eventName string, limit int64) ([]map[string]interface{}, error)

	// ClearEvents removes all events for a given event name
	ClearEvents(ctx context.Context, eventName string) error
}

EventStore defines the interface for event storage

type Mediator

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

Mediator manages event subscriptions and publishing

func GetMediator

func GetMediator() *Mediator

GetMediator returns the existing mediator instance

func New

func New() *Mediator

New creates a singleton Mediator instance

func (*Mediator) ClearEvents

func (m *Mediator) ClearEvents(ctx context.Context, eventName string) error

ClearEvents removes all events for a given event name

func (*Mediator) GetEvents

func (m *Mediator) GetEvents(ctx context.Context, eventName string, limit int64) ([]map[string]interface{}, error)

GetEvents retrieves events from the event store

func (*Mediator) Publish

func (m *Mediator) Publish(ctx context.Context, event Event) error

Publish sends an event to all registered handlers and stores it if event store is configured

func (*Mediator) SetEventStore

func (m *Mediator) SetEventStore(store EventStore)

SetEventStore sets the event store for the mediator

func (*Mediator) Subscribe

func (m *Mediator) Subscribe(eventName string, handler EventHandler)

Subscribe adds an event handler for a specific event type

Directories

Path Synopsis
extension

Jump to

Keyboard shortcuts

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