actions

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	Handle(ctx context.Context) (any, error)
}

Handler is the interface for declarative actions.

type Option

type Option = options.Option[Router]

Option configures a Router.

func WithAsyncEvents

func WithAsyncEvents(bus *events.Bus) Option

WithAsyncEvents emits the action instance asynchronously after dispatch.

func WithContainer

func WithContainer(container *di.Container) Option

WithContainer uses an existing DI container.

func WithEvents

func WithEvents(bus *events.Bus) Option

WithEvents emits the action instance after dispatch.

type Router

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

Router dispatches named actions and optional key bindings.

func New

func New(opts ...Option) *Router

New creates a Router.

func (*Router) Actions

func (r *Router) Actions() []string

Actions returns registered action names.

func (*Router) Build

func (r *Router) Build() (*di.Container, error)

Build constructs the DI container used during dispatch.

func (*Router) Dispatch

func (r *Router) Dispatch(ctx context.Context, name string, payload ...any) (any, error)

Dispatch executes an action by name.

func (*Router) DispatchKey

func (r *Router) DispatchKey(ctx context.Context, key string, payload ...any) (any, error)

DispatchKey executes an action by key binding.

func (*Router) Has

func (r *Router) Has(name string) bool

Has returns true if an action is registered.

func (*Router) KeyBindings

func (r *Router) KeyBindings() map[string]string

KeyBindings returns key-to-action mappings.

func (*Router) Provide

func (r *Router) Provide(name string, instance any)

Provide registers a named dependency for action handlers.

func (*Router) Register

func (r *Router) Register(prototype Handler)

Register registers an action handler.

func (*Router) UseAsyncEvents

func (r *Router) UseAsyncEvents(bus *events.Bus)

UseAsyncEvents emits the action instance asynchronously after dispatch.

func (*Router) UseContainer

func (r *Router) UseContainer(container *di.Container)

UseContainer replaces the DI container used during dispatch.

func (*Router) UseEvents

func (r *Router) UseEvents(bus *events.Bus)

UseEvents emits the action instance after dispatch.

Jump to

Keyboard shortcuts

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