Documentation ¶
Overview ¶
Package jsonrpc is a minimal JSON-RPC implementation
Package jsonrpc is a minimal JSON-RPC implementation
Index ¶
- Constants
- func SendJSONRPCRequestAndParseResult(req JSONRPCRequest, url string, reply interface{}) (err error)
- type DataError
- type Error
- type JSONRPCError
- type JSONRPCRequest
- type JSONRPCResponse
- func NewJSONRPCErrorResponse(id interface{}, code int, message string) *JSONRPCResponse
- func NewJSONRPCResponse(id interface{}, result json.RawMessage) *JSONRPCResponse
- func SendJSONRPCRequest(req JSONRPCRequest, url string) (res *JSONRPCResponse, err error)
- func SendNewJSONRPCRequest(id interface{}, method string, args interface{}, url string) (res *JSONRPCResponse, err error)
- type MockJSONRPCServer
Constants ¶
View Source
const ( ErrParse int = -32700 ErrInvalidRequest int = -32600 ErrMethodNotFound int = -32601 ErrInvalidParams int = -32602 ErrInternal int = -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 DataError ¶
type DataError interface { Error() string // returns the message ErrorData() interface{} // returns the error data }
type JSONRPCError ¶
type JSONRPCError struct { // A Number that indicates the error type that occurred. Code int `json:"code"` // A String providing a short description of the error. // The message SHOULD be limited to a concise single sentence. Message string `json:"message"` // A Primitive or Structured value that contains additional information about the error. Data interface{} `json:"data,omitempty"` /* optional */ }
JSONRPCError as per spec: https://www.jsonrpc.org/specification#error_object
func (*JSONRPCError) Error ¶
func (err *JSONRPCError) Error() string
func (*JSONRPCError) ErrorCode ¶
func (err *JSONRPCError) ErrorCode() int
func (*JSONRPCError) ErrorData ¶
func (err *JSONRPCError) ErrorData() interface{}
type JSONRPCRequest ¶
type JSONRPCRequest struct { ID interface{} `json:"id"` Method string `json:"method"` Params []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 ¶
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 ¶
type MockJSONRPCServer struct { Handlers map[string]func(req *JSONRPCRequest) (interface{}, error) RequestCounter sync.Map URL string // contains filtered or unexported fields }
func NewMockJSONRPCServer ¶
func NewMockJSONRPCServer() *MockJSONRPCServer
func (*MockJSONRPCServer) GetRequestCount ¶
func (s *MockJSONRPCServer) GetRequestCount(method string) int
func (*MockJSONRPCServer) IncrementRequestCounter ¶
func (s *MockJSONRPCServer) IncrementRequestCounter(method string)
func (*MockJSONRPCServer) SetHandler ¶
func (s *MockJSONRPCServer) SetHandler(method string, handler func(req *JSONRPCRequest) (interface{}, error))
Click to show internal directories.
Click to hide internal directories.