router API

router

package

API reference for the router package.

T
type

Handler

Re-export core types for convenience

pkg/router/router.go:14-14
type Handler core.Handler
T
type

Pattern

pkg/router/router.go:15-15
type Pattern core.Pattern
T
type

Meta

Meta is an alias for Pattern (backward compatibility with HTTP examples)

pkg/router/router.go:18-18
type Meta core.Pattern
F
function

HTTP

HTTP creates a new HTTP transport.

Returns

pkg/router/router.go:27-29
func HTTP() *http.Transport

{
	return http.New()
}
F
function

Action

Action creates a new Action transport for GUI/CLI apps.

Returns

pkg/router/router.go:32-34
func Action() *action.Transport

{
	return action.New()
}
S
struct

Router

Router is a convenience wrapper that provides both transports.

pkg/router/router.go:37-41
type Router struct

Methods

SetLogger
Method

SetLogger sets the logger for all transports.

Parameters

func (*Router) SetLogger(l logger.Logger)
{
	r.Logger = l
	r.HTTP.Logger = l
	r.Action.Logger = l
}
SetBus
Method

SetBus sets the event bus for action-based dispatching.

Parameters

b *bus.Bus
func (*Router) SetBus(b *bus.Bus)
{
	r.Action.Bus = b
}
Provide
Method

Provide registers a dependency in all transports.

Parameters

name string
instance any
func (*Router) Provide(name string, instance any)
{
	r.HTTP.Provide(name, instance)
	r.Action.Provide(name, instance)
}
Register
Method

Register registers a handler in the appropriate transport based on tags.

Parameters

prototype Handler
func (*Router) Register(prototype Handler)
{
	// For now, register in both if applicable
	// TODO: Detect which transport based on tags
	defer func() { recover() }()
	r.HTTP.Register(prototype)
}

RegisterAction registers an action handler.

Parameters

prototype Handler
func (*Router) RegisterAction(prototype Handler)
{
	r.Action.Register(prototype)
}
Listen
Method

Listen starts the HTTP transport.

Parameters

addr string

Returns

error
func (*Router) Listen(addr string) error
{
	return r.HTTP.Listen(addr)
}
Dispatch
Method

Dispatch dispatches an action with an optional payload.

Parameters

action string
payload ...any

Returns

any
error
func (*Router) Dispatch(ctx context.Context, action string, payload ...any) (any, error)
{
	return r.Action.Dispatch(ctx, action, payload...)
}
DispatchKey
Method

DispatchKey dispatches an action by keybinding.

Parameters

key string

Returns

any
error
func (*Router) DispatchKey(ctx context.Context, key string) (any, error)
{
	return r.Action.DispatchKey(ctx, key)
}
Handlers
Method

Handlers returns all registered HTTP handlers (for Swagger generation).

Returns

func (*Router) Handlers() []Handler
{
	return r.HTTP.Handlers()
}

Fields

Name Type Description
HTTP *http.Transport
Action *action.Transport
Logger logger.Logger
F
function

New

New creates a new multi-transport router.

Returns

pkg/router/router.go:44-50
func New() *Router

{
	return &Router{
		HTTP:   http.New(),
		Action: action.New(),
		Logger: logger.Nop,
	}
}