Help us shape the future of Go! Take the 2026 Go Developer Survey

rpc

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 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, 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 Error added in v0.4.0

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

Error represents a JSON-RPC error object.

func (*Error) Error added in v0.4.0

func (e *Error) 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   *Error `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