hook

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncHook

type AsyncHook interface {
	EventChan() chan<- schema.Event
	Filter() []string
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
}

AsyncHook is an asynchronous event observer that receives events via a channel. Start and Stop manage the consumer goroutine lifecycle. Filter returns the event types this hook cares about. An empty slice means all events are delivered.

type Hook

type Hook interface {
	OnEvent(ctx context.Context, event schema.Event) error
	Filter() []string
}

Hook is a synchronous event observer. OnEvent is called inline during dispatch and may be called concurrently from multiple goroutines; implementations must be safe for concurrent use and should be fast and non-blocking. Filter returns the event types this hook cares about. An empty slice means all events are delivered.

type HookFunc

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

HookFunc adapts a plain function into a Hook.

func NewHookFunc

func NewHookFunc(fn func(context.Context, schema.Event) error, types ...string) HookFunc

NewHookFunc creates a HookFunc with the given handler and optional event type filter.

func (HookFunc) Filter

func (h HookFunc) Filter() []string

Filter returns the configured event type filter.

func (HookFunc) OnEvent

func (h HookFunc) OnEvent(ctx context.Context, event schema.Event) error

OnEvent delegates to the wrapped function.

type Manager

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

Manager dispatches events to registered sync and async hooks. It is safe for concurrent use.

func NewManager

func NewManager() *Manager

NewManager creates an empty Manager.

func (*Manager) Dispatch

func (m *Manager) Dispatch(ctx context.Context, event schema.Event)

Dispatch sends an event to all matching hooks. Sync hooks are called sequentially; errors are logged but do not interrupt dispatch. Async hooks receive events via non-blocking channel send; full channels cause the event to be dropped with a warning log. Dispatch returns early if the context is cancelled. It is safe to call on a nil Manager.

func (*Manager) Register

func (m *Manager) Register(hooks ...Hook)

Register adds one or more synchronous hooks.

func (*Manager) RegisterAsync

func (m *Manager) RegisterAsync(hooks ...AsyncHook)

RegisterAsync adds one or more asynchronous hooks.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start starts all registered async hooks. If a hook fails to start, all previously started hooks are stopped to prevent goroutine leaks.

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

Stop stops all registered async hooks. It attempts to stop every hook and returns a combined error if any fail.

Jump to

Keyboard shortcuts

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