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

jsonrpc2

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 10 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 minimal JSON-RPC 2.0 client for stdio transport

func NewClient

func NewClient(stdin io.WriteCloser, stdout io.ReadCloser) *Client

NewClient creates a new JSON-RPC client

func (*Client) Notify

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

Notify sends a JSON-RPC notification (no response expected)

func (*Client) Request

func (c *Client) Request(method string, params any) (json.RawMessage, error)

Request sends a JSON-RPC request and waits for the response

func (*Client) SetOnClose added in v0.2.0

func (c *Client) SetOnClose(fn func())

SetOnClose sets a callback invoked when the read loop exits unexpectedly (e.g. the underlying connection or process was lost).

func (*Client) SetProcessDone added in v0.1.25

func (c *Client) SetProcessDone(done chan struct{}, errPtr *error)

SetProcessDone sets a channel that will be closed when the process exits, and stores the error that should be returned to pending/future requests.

func (*Client) SetRequestHandler

func (c *Client) SetRequestHandler(method string, handler RequestHandler)

SetRequestHandler registers a handler for incoming requests from the server

func (*Client) Start

func (c *Client) Start()

Start begins listening for messages in a background goroutine

func (*Client) Stop

func (c *Client) Stop()

Stop stops the client and cleans up

type Error

type Error struct {
	Code    int            `json:"code"`
	Message string         `json:"message"`
	Data    map[string]any `json:"data,omitempty"`
}

Error represents a JSON-RPC error response

func (*Error) Error

func (e *Error) Error() string

type NotificationHandler

type NotificationHandler func(method string, params json.RawMessage)

NotificationHandler handles incoming notifications

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id"` // nil for notifications
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params"`
}

Request represents a JSON-RPC 2.0 request

func (*Request) IsCall added in v0.1.24

func (r *Request) IsCall() bool

type RequestHandler

type RequestHandler func(params json.RawMessage) (json.RawMessage, *Error)

RequestHandler handles incoming server requests and returns a result or error

func NotificationHandlerFor added in v0.1.24

func NotificationHandlerFor[In any](handler func(params In)) RequestHandler

func RequestHandlerFor added in v0.1.24

func RequestHandlerFor[In, Out any](handler func(params In) (Out, *Error)) RequestHandler

RequestHandlerFor creates a RequestHandler from a typed function

type Response

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

Response represents a JSON-RPC 2.0 response

Jump to

Keyboard shortcuts

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