activity

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivityHook

type ActivityHook interface {
	Notify(ctx context.Context, event Event) error
}

ActivityHook receives normalized activity events.

type CaptureHook

type CaptureHook struct {
	Events []Event
	Err    error
	// contains filtered or unexported fields
}

CaptureHook records events for assertions in tests.

func (*CaptureHook) Notify

func (h *CaptureHook) Notify(_ context.Context, event Event) error

Notify records the event and returns any configured error.

type Config

type Config struct {
	Enabled bool
	Channel string
}

Config controls activity emission defaults supplied by DI/config.

type Emitter

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

Emitter fans out events to hooks while applying defaults.

func NewEmitter

func NewEmitter(hooks Hooks, cfg Config) *Emitter

NewEmitter constructs an emitter from hooks and configuration.

func (*Emitter) Emit

func (e *Emitter) Emit(ctx context.Context, event Event) error

Emit forwards the event to all hooks, applying default channel when missing.

func (*Emitter) Enabled

func (e *Emitter) Enabled() bool

Enabled reports whether emissions should be attempted.

type Event

type Event struct {
	Verb           string
	ActorID        string
	UserID         string
	TenantID       string
	ObjectType     string
	ObjectID       string
	Channel        string
	DefinitionCode string
	Recipients     []string
	Metadata       map[string]any
	OccurredAt     time.Time
}

Event describes an activity occurrence that can be fanned out to hooks. IDs are stringly-typed to avoid coupling call sites to specific UUID types.

func NormalizeEvent

func NormalizeEvent(event Event) Event

NormalizeEvent trims whitespace, clones metadata, and ensures a timestamp is present.

type HookFunc

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

HookFunc allows plain functions to satisfy ActivityHook.

func (HookFunc) Notify

func (fn HookFunc) Notify(ctx context.Context, event Event) error

Notify dispatches to the underlying function.

type Hooks

type Hooks []ActivityHook

Hooks fans out events to zero or more hooks.

func (Hooks) Enabled

func (h Hooks) Enabled() bool

Enabled reports whether there are any hooks to notify.

func (Hooks) Notify

func (h Hooks) Notify(ctx context.Context, event Event) error

Notify forwards the event to all hooks, returning a joined error if any fail. It normalizes the event, short-circuiting when required fields are missing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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