jsonrpc

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 7 Imported by: 3

Documentation

Overview

Package jsonrpc is a minimal JSON-RPC implementation

Package jsonrpc is a minimal JSON-RPC implementation

Index

Constants

View Source
const (
	ParseError     = -32700
	InvalidRequest = -32600
	MethodNotFound = -32601
	InvalidParams  = -32602
	InternalError  = -32603
)

As per JSON-RPC 2.0 Specification https://www.jsonrpc.org/specification#error_object

Variables

This section is empty.

Functions

func SendJSONRPCRequestAndParseResult

func SendJSONRPCRequestAndParseResult(req JSONRPCRequest, url string, reply interface{}) (err error)

SendJSONRPCRequestAndParseResult sends the request and decodes the response into the reply interface. If the JSON-RPC response contains an Error property, the it's returned as this function's error.

Types

type JSONRPCError

type JSONRPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

JSONRPCError as per spec: https://www.jsonrpc.org/specification#error_object

func (JSONRPCError) Error

func (err JSONRPCError) Error() string

type JSONRPCRequest

type JSONRPCRequest struct {
	ID      interface{}    `json:"id"`
	Method  string         `json:"method"`
	Params  [1]interface{} `json:"params"`
	Version string         `json:"jsonrpc,omitempty"`
}

func NewJSONRPCRequest

func NewJSONRPCRequest(id interface{}, method string, args interface{}) *JSONRPCRequest

type JSONRPCResponse

type JSONRPCResponse struct {
	ID      interface{}     `json:"id"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *JSONRPCError   `json:"error,omitempty"`
	Version string          `json:"jsonrpc"`
}

func NewJSONRPCErrorResponse

func NewJSONRPCErrorResponse(id interface{}, code int, message string) *JSONRPCResponse

func NewJSONRPCResponse

func NewJSONRPCResponse(id interface{}, result json.RawMessage) *JSONRPCResponse

func SendJSONRPCRequest

func SendJSONRPCRequest(req JSONRPCRequest, url string) (res *JSONRPCResponse, err error)

SendJSONRPCRequest sends the request to URL and returns the general JsonRpcResponse, or an error (note: not the JSONRPCError)

func SendNewJSONRPCRequest added in v0.2.1

func SendNewJSONRPCRequest(id interface{}, method string, args interface{}, url string) (res *JSONRPCResponse, err error)

SendNewJSONRPCRequest constructs a request and sends it to the URL

type MockJSONRPCServer added in v0.3.1

type MockJSONRPCServer struct {
	URL string
	// contains filtered or unexported fields
}

func NewMockJSONRPCServer added in v0.3.1

func NewMockJSONRPCServer() *MockJSONRPCServer

Jump to

Keyboard shortcuts

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