jsonrpc

package
v0.0.0-...-1b8d500 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package jsonrpc is a minimal JSON-RPC 1.0 implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestNetConn

func TestNetConn(t *testing.T, fn TestFunc) (net.Conn, chan<- *Response, func())

TestNetConn creates a net.Conn backed by a server that calls a TestFunc. Notifications can be pushed to the client using the channel. Invoke the returned closure to clean up its resources.

Types

type Conn

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

A Conn is a JSON-RPC connection.

func NewConn

func NewConn(rwc io.ReadWriteCloser, ll *log.Logger) *Conn

NewConn creates a new Conn with the input io.ReadWriteCloser. If a logger is specified, it is used for debug logs.

func TestConn

func TestConn(t *testing.T, fn TestFunc) (*Conn, chan<- *Response, func())

TestConn creates a Conn backed by a server that calls a TestFunc. Notifications can be pushed to the client using the channel. Invoke the returned closure to clean up its resources.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) Receive

func (c *Conn) Receive() (*Response, error)

Receive receives a single JSON-RPC response.

func (*Conn) Send

func (c *Conn) Send(req Request) error

Send sends a single JSON-RPC request.

type Request

type Request struct {
	ID     string      `json:"id"`
	Method string      `json:"method"`
	Params interface{} `json:"params"`
}

A Request is a JSON-RPC request.

type Response

type Response struct {
	// Non-null for response; null for request notification.
	ID *string `json:"id"`

	// Response fields.
	Result json.RawMessage `json:"result,omitempty"`
	Error  interface{}     `json:"error"`

	// Request notification fields.
	Method string          `json:"method,omitempty"`
	Params json.RawMessage `json:"params,omitempty"`
}

A Response is either a JSON-RPC response, or a JSON-RPC request notification.

func (*Response) Err

func (r *Response) Err() error

Err returns an error, if one occurred in a Response.

type TestFunc

type TestFunc func(req Request) Response

A TestFunc is used to create RPC responses in TestConn.

Jump to

Keyboard shortcuts

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