jsonrpc

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version = "2.0" // JSON-RPC protocol version
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code    ErrorCode   `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

Error represents a JSON-RPC error object

func NewError

func NewError(code ErrorCode, data interface{}) *Error

NewError creates a new JSON-RPC error with the given code and optional data

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode int

ErrorCode represents a JSON-RPC error code

const (
	// Parse error (-32700)
	// Invalid JSON was received by the server.
	// An error occurred on the server while parsing the JSON text.
	ErrParse ErrorCode = -32700

	// Invalid Request (-32600)
	// The JSON sent is not a valid Request object.
	ErrInvalidRequest ErrorCode = -32600

	// Method not found (-32601)
	// The method does not exist / is not available.
	ErrMethodNotFound ErrorCode = -32601

	// Invalid params (-32602)
	// Invalid method parameter(s).
	ErrInvalidParams ErrorCode = -32602

	// Internal error (-32603)
	// Internal JSON-RPC error.
	ErrInternal ErrorCode = -32603

	// Server error (-32000 to -32099)
	// Reserved for implementation-defined server-errors.
	ErrServer ErrorCode = -32000
)

JSON-RPC 2.0 error codes as defined in https://www.jsonrpc.org/specification

type ID

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

ID represents a JSON-RPC ID which must be either a string or number

func NewID

func NewID(id interface{}) (ID, error)

NewID creates a JSON-RPC ID from a string or number

func (ID) Equal

func (id ID) Equal(other interface{}) bool

Equal compares two IDs for equality

func (ID) GoString

func (id ID) GoString() string

GoString implements fmt.GoStringer

func (ID) IsNil

func (id ID) IsNil() bool

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

func (ID) Value

func (id ID) Value() interface{}

type Request

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

Request represents a JSON-RPC request object

func NewRequest

func NewRequest(method string, params json.RawMessage, id interface{}) Request

NewRequest creates a new Request object

type Response

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

Response represents a JSON-RPC response object

func NewResponse

func NewResponse(id interface{}, result Result, err *Error) Response

NewResponse creates a new Response object

type Result

type Result interface{}

Result represents a map of string keys to arbitrary values

Jump to

Keyboard shortcuts

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