jsonrpc

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "2.0"

Version is the JSON-RPC protocol version.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

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

Error represents a JSON-RPC 2.0 error.

type Push

type Push struct {
	JSONRPC string `json:"jsonrpc"`
	Method  string `json:"method"`
	Data    any    `json:"data,omitempty"`
}

Push represents a server-initiated push message (no ID, not tied to a request).

func NewPush

func NewPush(method string, data any) *Push

NewPush creates a server-initiated push message (not tied to any request).

type Request

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

Request represents a JSON-RPC 2.0 request.

func (*Request) IsNotification

func (r *Request) IsNotification() bool

IsNotification returns true if the request is a notification (no ID).

type Response

type Response struct {
	JSONRPC string `json:"jsonrpc"`
	Method  string `json:"method,omitempty"` // For notifications
	Result  any    `json:"result,omitempty"`
	Error   *Error `json:"error,omitempty"`
	ID      any    `json:"id,omitempty"`
}

Response represents a JSON-RPC 2.0 response.

func NewErrorResponse

func NewErrorResponse(id any, err error) *Response

NewErrorResponse creates an error response from an error.

func NewResponse

func NewResponse(id any, result any) *Response

NewResponse creates a success response.

func NewStreamResponse

func NewStreamResponse(id any, method string, result any) *Response

NewStreamResponse creates a response for streaming scenarios with method identifier.

Jump to

Keyboard shortcuts

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