jsonrpc

package
v0.0.0-...-dc54953 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const ContentType = "application/json"

ContentType is the MIME Type expected of clients and returned by the server.

Variables

This section is empty.

Functions

func HTTP

func HTTP(hf Handler) http.Handler

HTTP adapts a JSON-RPC Handler to a HTTP Handler for use in HTTP(S) exchanges.

Types

type Error

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

	Data interface{} `json:"data,omitempty"`
}

Error implements a top-level JSON-RPC error.

func InternalError

func InternalError(message string, data interface{}) *Error

InternalError returns a JSON-RPC Internal Server error (-32603).

func InvalidParams

func InvalidParams(message string, data interface{}) *Error

InvalidParams returns a JSON-RPC Invalid Params error (-32602).

func InvalidRequest

func InvalidRequest(message string, data interface{}) *Error

InvalidRequest returns a JSON-RPC Invalid Request error (-32600).

func MethodNotFound

func MethodNotFound(message string, data interface{}) *Error

MethodNotFound returns a JSON-RPC Method Not Found error (-32601).

func ParseError

func ParseError(message string, data interface{}) *Error

ParseError returns a JSON-RPC Parse Error (-32700).

func ServerError

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

ServerError returns a JSON-RPC Server Error, which must be given a code between -32000 and -32099.

func (Error) Error

func (e Error) Error() string

type Handler

type Handler interface {
	ServeJSONRPC(w ResponseWriter, r *Request)
}

Handler responds to JSON-RPC requests.

type HandlerFunc

type HandlerFunc func(ResponseWriter, *Request)

HandlerFunc adapts a function into a handler.

func (HandlerFunc) ServeJSONRPC

func (hf HandlerFunc) ServeJSONRPC(w ResponseWriter, r *Request)

ServeJSONRPC responds to JSON-RPC requests with hf(w, r).

type Request

type Request struct {
	Version string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
	ID      json.RawMessage `json:"id"`
	// contains filtered or unexported fields
}

Request contains the JSON-RPC paramaters submitted by the client.

func (*Request) Context

func (r *Request) Context() context.Context

Context returns the execution context of the request, or the background context if one is not set.

func (*Request) RemoteAddr

func (r *Request) RemoteAddr() string

RemoteAddr returns the remote ip:port of the client.

type ResponseWriter

type ResponseWriter interface {
	// Write marshals anything given to it as the Result of the JSON-RPC
	// interaction. If the given argument implements then Error interface,
	// it will be marshalled as the Error.
	Write(interface{}) error
}

ResponseWriter marshals the JSON-RPC response to the client.

Jump to

Keyboard shortcuts

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