Documentation ¶
Index ¶
Constants ¶
View Source
const ( // ErrServer Reserved for implementation-defined server-errors. ErrServer = -32000 // ErrInvalidRequest The JSON sent is not a valid Request object. ErrInvalidRequest = -32600 // ErrNoMethod The method does not exist / is not available. ErrNoMethod = -32601 // ErrBadParams Invalid method parameter(s). ErrBadParams = -32602 // ErrInternal Internal JSON-RPC error. ErrInternal = -32603 // ErrParse Invalid JSON was received by the server. // An error occurred on the server while parsing the JSON text. ErrParse = -32700 )
View Source
const Version = "2.0"
Version of json-rpc protocol
Variables ¶
View Source
var ( // DefaultEncoder for request DefaultEncoder = &encoder{} // DefaultEncoderSelector for request DefaultEncoderSelector = &encoderSelector{} )
Functions ¶
Types ¶
type CompressionSelector ¶
type CompressionSelector struct{}
CompressionSelector generates the compressed http encoder.
type Encoder ¶
type Encoder interface {
Encode(w http.ResponseWriter) io.Writer
}
Encoder interface contains the encoder for http response. Eg. gzip, flate compressions.
type EncoderSelector ¶
EncoderSelector interface provides a way to select encoder using the http request. Typically people can use this to check HEADER of the request and figure out client capabilities. Eg. "Accept-Encoding" tells about supported compressions.
type Error ¶
type Error struct { // A Number that indicates the error type that occurred. Code int `json:"code"` /* required */ // A String providing a short description of the error. // The message SHOULD be limited to a concise single sentence. Message string `json:"message"` /* required */ // A Primitive or Structured value that contains additional information about the error. Data interface{} `json:"data,omitempty"` /* optional */ Internal error `json:"-"` // ignore }
Error is codec error representation
type Interface ¶
Interface codec creates a CodecRequest to process each request.
func NewCustom ¶
func NewCustom(encSel EncoderSelector) Interface
NewCustom returns a new JSON codec based on passed encoder selector.
type Request ¶
type Request interface { // HandleError from input and request instance HandleError(err error) bool // Reads the request and returns the RPC method name. Method() string // Reads the request filling the RPC method args. ReadRequest(interface{}) error // Writes the response using the RPC method reply. WriteResponse(interface{}) // Writes an error produced by the server. WriteError(status int, err error) }
Request decodes a request and encodes a response using a specific serialization scheme.
Click to show internal directories.
Click to hide internal directories.