jsonrpc

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParseErrorCode     = -32700
	InvalidRequestCode = -32600
	MethodNotFoundCode = -32601
	InvalidParamsCode  = -32602
	InternalErrorCode  = -32603
)

Standard error codes

View Source
const Version = "2.0"

Version is the JSON-RPC version string

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

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

Error represents a JSON-RPC error

func InternalError

func InternalError(data interface{}) *Error

InternalError creates an Internal Error

func InvalidParamsError

func InvalidParamsError(data interface{}) *Error

InvalidParamsError creates an Invalid Params error

func InvalidRequestError

func InvalidRequestError(data interface{}) *Error

InvalidRequestError creates an Invalid Request error

func MethodNotFoundError

func MethodNotFoundError(method string) *Error

MethodNotFoundError creates a Method Not Found error

func NewError

func NewError(code int, message string, data interface{}) *Error

NewError creates a new Error with the given code and message

func ParseError

func ParseError(data interface{}) *Error

ParseError creates a Parse Error

func (*Error) Error

func (e *Error) Error() string

Error returns a string representation of the error

type Request

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

Request represents a JSON-RPC request

func (*Request) IsNotification

func (r *Request) IsNotification() bool

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

type Response

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

Response represents a JSON-RPC response

func NewResponse

func NewResponse(req *Request, result interface{}, err *Error) *Response

NewResponse creates a new response for the given request

Jump to

Keyboard shortcuts

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