jsonrpc

package
v0.0.0-...-c276f64 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

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 is a generic JSON RPC 2.0 client, which is able to invoke remote methods and subscribe to remote notifications.

func Connect

func Connect(opts *Options) (*Client, error)

Connect creates a new JSON RPC client. It returns an error if the connection fails.

func (*Client) Close

func (c *Client) Close()

Close closes the connection and shuts down all pending requests. All pending requests will be resolved with an error.

func (*Client) Method

func (c *Client) Method(
	ctx context.Context,
	onResponse func([]byte, error),
	method string,
	params ...interface{}) error

Method invokes a JSON RPC method. onResponse is called either with the response, or with an error if the context finished (cancelled or timeout).

func (*Client) MethodBlocking

func (c *Client) MethodBlocking(ctx context.Context, response interface{}, method string, params ...interface{}) error

MethodBlocking is like `Method`, but blocking until there is a response. The json response is JSON unmarshalled into `response`.

func (*Client) OnNotification

func (c *Client) OnNotification(onNotification func(method string, params json.RawMessage))

OnNotification defines a callback that is called when a JSON RPC notification is received. `params` are JSON bytes and should be unmarshalled into the an appropriate type.

func (*Client) SetOnError

func (c *Client) SetOnError(f func(error))

SetOnError defines a callback that is called when there is a processing error in the socket read loop, e.g. a `SocketError` if there was a socket read error, or any other error if a JSON RPC read could not be deserialized or is otherwise invalid.

type Options

type Options struct {
	// Dial connects to the server and returns a connection object.
	Dial func() (net.Conn, error)
}

Options to configure the JSON RPC client.

type SocketError

type SocketError error

SocketError is an error writing to or reading from a socket.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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