Documentation
¶
Overview ¶
Package dispatch routes addressed deliveries to handlers and provides the request, response and event helpers adapters use. A Dispatcher owns one endpoint attachment and an explicit exact/longest-prefix routing policy; Call and Emit send through any addressed access; Handle and Register run a body per request or event with the context its carrier established.
Index ¶
- func Call(ctx context.Context, access wire.AddressedWire, path []string, ...) error
- func Emit(ctx context.Context, access wire.AddressedWire, path []string, data any, ...) error
- func Handle(registry Registry, path []string, handler Handler) (func(), error)
- func Register(registry Registry, path []string, handlers Handlers) (func(), error)
- type CallOptions
- type Dispatcher
- func (d *Dispatcher) Close(code wire.Code, reason string) error
- func (d *Dispatcher) Register(path []string, receiver wire.Receiver) (func(), error)
- func (d *Dispatcher) RegisterPrefix(path []string, receiver wire.Receiver) (func(), error)
- func (d *Dispatcher) Select(path []string) *SelectedEndpoint
- func (d *Dispatcher) Send(path []string, message wire.Message) error
- type DispatcherOptions
- type EmitOptions
- type EventHandler
- type Handler
- type Handlers
- type Registry
- type SelectedEndpoint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Call ¶
func Call(ctx context.Context, access wire.AddressedWire, path []string, params, result any, options ...CallOptions) error
Call sends one request at a relative path and waits for its response, decoding a success into result when it is not nil. Its return capability is fresh for this call and carries the invocation lifecycle, so it is independent of every other call's identifier. A caller that withdraws — ctx ends first — sends a best-effort cancellation. It never retries.
A refusal before anything was sent is an *core.UnpublishedError; a response error is a *core.PublicError.
func Emit ¶
func Emit(ctx context.Context, access wire.AddressedWire, path []string, data any, options ...EmitOptions) error
Emit admits one event at a relative path. Success says only that the destination accepted it; processing and transport remain asynchronous.
Types ¶
type CallOptions ¶
type CallOptions struct {
Propagator core.Propagator
Timeout time.Duration
}
CallOptions configures one call, independently of its carrier. A zero Timeout waits 30 seconds; a nil Propagator uses core.DefaultPropagator.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher owns one endpoint attachment and an explicit exact/longest-prefix routing policy. It captures each request's traversal on the invocation its return capability carries, through the public vocabulary alone, and refuses a request whose return capability carries none rather than routing it with weaker detach and cancellation guarantees. An opaque wrapper is therefore as good as a native endpoint: the lifecycle travels with the unchanged return capability, and nothing here recognizes a concrete type. A cancellation goes to the traversal that captured its request, never to the route now in force.
func NewDispatcher ¶
func NewDispatcher(root wire.Endpoint, options ...DispatcherOptions) (*Dispatcher, error)
NewDispatcher attaches to root and routes what it delivers. The endpoint is borrowed unless options transfer its closure.
func (*Dispatcher) Close ¶
func (d *Dispatcher) Close(code wire.Code, reason string) error
Close releases the routes and the root attachment, and closes the root only when this dispatcher owns it.
func (*Dispatcher) Register ¶
func (d *Dispatcher) Register(path []string, receiver wire.Receiver) (func(), error)
Register routes exactly path to receiver. A path has one registration.
func (*Dispatcher) RegisterPrefix ¶
func (d *Dispatcher) RegisterPrefix(path []string, receiver wire.Receiver) (func(), error)
RegisterPrefix routes path and every path beneath it, the longest registered prefix winning, unless an exact registration matches.
func (*Dispatcher) Select ¶
func (d *Dispatcher) Select(path []string) *SelectedEndpoint
Select returns a receiving view of this shared dispatcher. The view owns its prefix route and never acquires closure authority over the root endpoint.
type DispatcherOptions ¶
type DispatcherOptions struct{ OwnEndpoint bool }
DispatcherOptions explicitly transfers closure authority for an endpoint the caller owns. Borrowed endpoints remain the default.
type EmitOptions ¶
type EmitOptions struct {
Propagator core.Propagator
}
EmitOptions configures one event emission; a nil Propagator uses core.DefaultPropagator.
type EventHandler ¶
type EventHandler func(context.Context, json.RawMessage) error
EventHandler receives an event body beside the context it was carried with. An error ends the registry's endpoint as a protocol error.
type Handler ¶
Handler is a request body, independent of the carrier. It takes the params as they arrived and returns the result, or an error: a *core.PublicError crosses with its code, a cancellation as cancelled, and any other error as internal. Its context carries the trace and meta the request brought, and ends when the caller withdraws or the deadline passes.
type Handlers ¶
type Handlers struct {
Request Handler
Event EventHandler
}
Handlers groups a request body and an event body that share one path.
type Registry ¶
type Registry interface {
wire.AddressedWire
Register([]string, wire.Receiver) (func(), error)
Close(wire.Code, string) error
}
Registry is the registration capability Handle and Register need: send access plus explicit route registration. Closing it releases its registrations, not a borrowed carrier.
type SelectedEndpoint ¶
type SelectedEndpoint struct {
// contains filtered or unexported fields
}
SelectedEndpoint is a receiving view of a shared dispatcher at a prefix.
func (*SelectedEndpoint) Close ¶
func (s *SelectedEndpoint) Close(code wire.Code, reason string) error
Close ends the view's route; it never closes the shared root.
func (*SelectedEndpoint) Receive ¶
func (s *SelectedEndpoint) Receive(receiver wire.Receiver) (func(), error)
Receive attaches the view's one receiver, which sees paths relative to the view's prefix.
func (*SelectedEndpoint) Select ¶
func (s *SelectedEndpoint) Select(path []string) *SelectedEndpoint
Select narrows the view by a further prefix.