Documentation
¶
Index ¶
- Constants
- func HTTP(hf Handler) http.Handler
- type Error
- func InternalError(message string, data interface{}) *Error
- func InvalidParams(message string, data interface{}) *Error
- func InvalidRequest(message string, data interface{}) *Error
- func MethodNotFound(message string, data interface{}) *Error
- func ParseError(message string, data interface{}) *Error
- func ServerError(code int, message string, data interface{}) *Error
- type Handler
- type HandlerFunc
- type Request
- type ResponseWriter
Constants ¶
const ContentType = "application/json"
ContentType is the MIME Type expected of clients and returned by the server.
Variables ¶
This section is empty.
Functions ¶
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 ¶
InternalError returns a JSON-RPC Internal Server error (-32603).
func InvalidParams ¶
InvalidParams returns a JSON-RPC Invalid Params error (-32602).
func InvalidRequest ¶
InvalidRequest returns a JSON-RPC Invalid Request error (-32600).
func MethodNotFound ¶
MethodNotFound returns a JSON-RPC Method Not Found error (-32601).
func ParseError ¶
ParseError returns a JSON-RPC Parse Error (-32700).
func ServerError ¶
ServerError returns a JSON-RPC Server Error, which must be given a code between -32000 and -32099.
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 ¶
Context returns the execution context of the request, or the background context if one is not set.
func (*Request) RemoteAddr ¶
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.