rpc

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 6 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 JSON-RPC 2.0 test client connected to an in-memory pipe.

func DialJSONRPC

func DialJSONRPC(t testing.TB, serve func(ctx context.Context, in io.Reader, out io.Writer) error) *Client

DialJSONRPC creates a client and runs serve in a goroutine over net.Pipe.

func (*Client) Call

func (c *Client) Call(method string, params any, id any) Response

Call sends a JSON-RPC request and waits for the matching response.

func (*Client) CallRaw

func (c *Client) CallRaw(payload string) Response

CallRaw sends a raw payload line and reads a response.

func (*Client) Close

func (c *Client) Close() error

Close closes the client connection.

func (*Client) Notify

func (c *Client) Notify(method string, params any) error

Notify sends a JSON-RPC notification (no ID, no response).

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

RPCError represents a JSON-RPC error object.

func (*RPCError) Error

func (e *RPCError) Error() string

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      any             `json:"id,omitempty"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

Request is a JSON-RPC 2.0 request object.

type Response

type Response struct {
	JSONRPC string    `json:"jsonrpc"`
	ID      any       `json:"id,omitempty"`
	Result  any       `json:"result,omitempty"`
	Error   *RPCError `json:"error,omitempty"`
}

Response is a JSON-RPC 2.0 response object.

func (*Response) BindResult

func (r *Response) BindResult(t testing.TB, v any)

BindResult unmarshals a successful result into v.

Jump to

Keyboard shortcuts

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