rpc

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package rpc provides a JSON-RPC 2.0 server implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents a connected RPC client.

func NewClient

func NewClient(t transport.Transport, dispatcher *handler.Dispatcher) *Client

NewClient creates a new RPC client.

func (*Client) Close

func (c *Client) Close() error

Close closes the client connection.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done returns a channel that's closed when the client is done.

func (*Client) ID

func (c *Client) ID() string

ID returns the client's unique identifier.

func (*Client) Send

func (c *Client) Send(data []byte) error

Send queues a message for sending.

func (*Client) SendEvent

func (c *Client) SendEvent(event events.Event) error

Send implements ports.Subscriber.Send. Converts events to JSON-RPC notifications.

func (*Client) SendNotification

func (c *Client) SendNotification(method string, params interface{}) error

SendNotification sends a JSON-RPC notification.

func (*Client) Serve

func (c *Client) Serve(ctx context.Context) error

Serve handles the client's message loop. This method blocks until the client disconnects.

type EventAdapter

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

EventAdapter wraps a Client to implement ports.Subscriber.

func NewEventAdapter

func NewEventAdapter(client *Client) *EventAdapter

NewEventAdapter creates a new event adapter.

func (*EventAdapter) Close

func (a *EventAdapter) Close() error

Close implements ports.Subscriber.

func (*EventAdapter) Done

func (a *EventAdapter) Done() <-chan struct{}

Done implements ports.Subscriber.

func (*EventAdapter) ID

func (a *EventAdapter) ID() string

ID implements ports.Subscriber.

func (*EventAdapter) Send

func (a *EventAdapter) Send(event events.Event) error

Send implements ports.Subscriber.

type Server

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

Server handles JSON-RPC communication over a transport.

func NewServer

func NewServer(dispatcher *handler.Dispatcher, hub ports.EventHub) *Server

NewServer creates a new RPC server.

func (*Server) Broadcast

func (s *Server) Broadcast(method string, params interface{}) error

Broadcast sends a notification to all connected clients.

func (*Server) ClientCount

func (s *Server) ClientCount() int

ClientCount returns the number of connected clients.

func (*Server) ServeTransport

func (s *Server) ServeTransport(ctx context.Context, t transport.Transport) error

ServeTransport handles a single transport connection. This method blocks until the transport is closed or the server is stopped.

func (*Server) Stop

func (s *Server) Stop() error

Stop gracefully stops the server.

Directories

Path Synopsis
Package handler provides OpenRPC spec generation from the method registry.
Package handler provides OpenRPC spec generation from the method registry.
methods
Package methods provides JSON-RPC method implementations.
Package methods provides JSON-RPC method implementations.
Package message defines JSON-RPC 2.0 message types.
Package message defines JSON-RPC 2.0 message types.
Package transport provides transport layer abstractions for RPC communication.
Package transport provides transport layer abstractions for RPC communication.

Jump to

Keyboard shortcuts

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