Documentation
¶
Index ¶
- type Client
- func (c *Client) Close()
- func (c *Client) Method(ctx context.Context, onResponse func([]byte, error), method string, ...) error
- func (c *Client) MethodBlocking(ctx context.Context, response interface{}, method string, ...) error
- func (c *Client) OnNotification(onNotification func(method string, params json.RawMessage))
- func (c *Client) SetOnError(f func(error))
- type Options
- type SocketError
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 (*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 ¶
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.