Documentation ¶
Overview ¶
Package jsonrpc implements a JSONRPC2.0 compliant server as described in https://www.jsonrpc.org/specification
Index ¶
Constants ¶
const ( InvalidJSON = -32700 // Invalid JSON was received by the server. InvalidRequest = -32600 // The JSON sent is not a valid Request object. MethodNotFound = -32601 // The method does not exist / is not available. InvalidParams = -32602 // Invalid method parameter(s). InternalError = -32603 // Internal JSON-RPC error. )
const MaxRequestBodySize = 10 * 1024 * 1024 // 10MB
Variables ¶
var ErrInvalidID = errors.New("id should be a string or an integer")
Functions ¶
This section is empty.
Types ¶
type Error ¶
type HTTP ¶ added in v0.2.1
type HTTP struct {
// contains filtered or unexported fields
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(log utils.SimpleLogger) *Server
NewServer instantiates a JSONRPC server
func (*Server) Handle ¶
Handle processes a request to the server It returns the response in a byte array, only returns an error if it can not create the response byte array
func (*Server) HandleReader ¶
HandleReader processes a request to the server It returns the response in a byte array, only returns an error if it can not create the response byte array
func (*Server) RegisterMethod ¶
RegisterMethod verifies and creates an endpoint that the server recognises.
- name is the method name - handler is the function to be called when a request is received for the associated method. It should have (any, *jsonrpc.Error) as its return type - paramNames are the names of parameters in the order that they are expected by the handler
func (*Server) WithValidator ¶ added in v0.4.0
WithValidator registers a validator to validate handler struct arguments
type Websocket ¶ added in v0.4.0
type Websocket struct {
// contains filtered or unexported fields
}
func NewWebsocket ¶ added in v0.4.0
func (*Websocket) Handler ¶ added in v0.4.0
Handler processes an HTTP request and upgrades it to a websocket connection. The connection's entire "lifetime" is spent in this function.
func (*Websocket) WithConnParams ¶ added in v0.4.0
func (ws *Websocket) WithConnParams(p *WebsocketConnParams) *Websocket
WithConnParams sanity checks and applies the provided params.
type WebsocketConnParams ¶ added in v0.4.0
type WebsocketConnParams struct { // Maximum message size allowed. ReadLimit int64 // Maximum time to write a message. WriteDuration time.Duration // Maximum time to read a message. ReadDuration time.Duration }
func DefaultWebsocketConnParams ¶ added in v0.4.0
func DefaultWebsocketConnParams() *WebsocketConnParams