events

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseEvent

type BaseEvent struct {
	Occurred time.Time
}

func (BaseEvent) OccurredAt

func (e BaseEvent) OccurredAt() time.Time

type Bus

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

Bus is a simple in-memory event bus.

func NewBus

func NewBus() *Bus

NewBus creates a new event bus.

func (*Bus) Publish

func (b *Bus) Publish(eventType string, event interface{})

Publish publishes an event to all registered handlers.

func (*Bus) Subscribe

func (b *Bus) Subscribe(eventType string, handler EventHandler)

Subscribe registers a handler for the given event type.

func (*Bus) SubscribeOnce

func (b *Bus) SubscribeOnce(eventType string, handler EventHandler)

SubscribeOnce registers a handler that will be called only once for the given event type.

func (*Bus) Unsubscribe

func (b *Bus) Unsubscribe(eventType string, handler EventHandler)

Unsubscribe removes a handler for the given event type. Note: This implementation does not actually remove the handler because we don't have a way to identify it. In a real implementation, you might return a subscription object that can be used to unsubscribe.

type Event

type Event interface {
	Name() string
	Version() int
	OccurredAt() time.Time
}

type EventBus

type EventBus interface {
	Subscribe(eventName string, handler Handler)
	Publish(ctx context.Context, event Event) error
}

type EventHandler

type EventHandler func(event interface{})

EventHandler is a function that handles an event.

type FileUploaded

type FileUploaded struct {
	BaseEvent
	TenantID string
	ObjectID string
	Path     string
}

func (FileUploaded) Name

func (e FileUploaded) Name() string

func (FileUploaded) Version

func (e FileUploaded) Version() int

type Handler

type Handler func(context.Context, Event) error

type InMemoryBus

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

func NewInMemoryBus

func NewInMemoryBus() *InMemoryBus

func (*InMemoryBus) Publish

func (b *InMemoryBus) Publish(ctx context.Context, event Event) error

func (*InMemoryBus) Subscribe

func (b *InMemoryBus) Subscribe(eventName string, handler Handler)

type NotificationQueued

type NotificationQueued struct {
	BaseEvent
	TenantID string
	Channel  string
	Message  string
}

func (NotificationQueued) Name

func (e NotificationQueued) Name() string

func (NotificationQueued) Version

func (e NotificationQueued) Version() int

type TenantProvisioned

type TenantProvisioned struct {
	BaseEvent
	TenantID   string
	TenantName string
}

func (TenantProvisioned) Name

func (e TenantProvisioned) Name() string

func (TenantProvisioned) Version

func (e TenantProvisioned) Version() int

type UserCreated

type UserCreated struct {
	BaseEvent
	UserID   string
	TenantID string
	Email    string
}

func (UserCreated) Name

func (e UserCreated) Name() string

func (UserCreated) Version

func (e UserCreated) Version() int

Jump to

Keyboard shortcuts

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