spec

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Index

Constants

View Source
const (
	InvalidParamsErrorCode  int = -32602
	MethodNotFoundErrorCode int = -32601
	InvalidRequestErrorCode int = -32600
	ServerErrorCode         int = -32000
)
View Source
const JSONRPCVersion = "2.0"

Variables

This section is empty.

Functions

func IsValidBaseRequest

func IsValidBaseRequest(baseRequest *BaseJSONRequest) bool

IsValidBaseRequest validates that the base JSON request is valid

Types

type BaseJSON

type BaseJSON struct {
	JSONRPC string `json:"jsonrpc"`
	ID      uint   `json:"id"`
}

BaseJSON defines the base JSON fields all JSON-RPC requests and responses need to have

type BaseJSONError

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

BaseJSONError defines the base JSON response error format

func GenerateResponseError

func GenerateResponseError(err error) *BaseJSONError

GenerateResponseError generates the JSON-RPC server error response

func NewJSONError

func NewJSONError(message string, code int) *BaseJSONError

NewJSONError creates a new JSON-RPC error

type BaseJSONRequest

type BaseJSONRequest struct {
	BaseJSON

	Method string          `json:"method"`
	Params []any           `json:"params"`
	Meta   json.RawMessage `json:"meta"`
}

BaseJSONRequest defines the base JSON request format

func NewJSONRequest

func NewJSONRequest(
	id uint,
	method string,
	params []any,
) *BaseJSONRequest

NewJSONRequest creates a new JSON-RPC request

type BaseJSONRequests

type BaseJSONRequests []*BaseJSONRequest

BaseJSONRequests represents a batch of JSON-RPC requests

func ExtractBaseRequests

func ExtractBaseRequests(requestBody []byte) (BaseJSONRequests, error)

ExtractBaseRequests extracts the base JSON-RPC request from the request body

type BaseJSONResponse

type BaseJSONResponse struct {
	Result any            `json:"result,omitempty"`
	Error  *BaseJSONError `json:"error,omitempty"`
	BaseJSON
}

BaseJSONResponse defines the base JSON response format

func NewJSONResponse

func NewJSONResponse(
	id uint,
	result any,
	err *BaseJSONError,
) *BaseJSONResponse

NewJSONResponse creates a new JSON-RPC response

type BaseJSONResponses

type BaseJSONResponses []*BaseJSONResponse

BaseJSONResponses represents a batch of JSON-RPC responses

Jump to

Keyboard shortcuts

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