Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec struct {
// contains filtered or unexported fields
}
Codec creates a CodecRequest to process each request.
func NewCustomCodec ¶
func NewCustomCodec(encSel rpc.EncoderSelector) *Codec
NewCustomCodec returns a new JSON Codec based on passed encoder selector.
func NewCustomCodecWithErrorMapper ¶
func NewCustomCodecWithErrorMapper(encSel rpc.EncoderSelector, errorMapper func(error) error) *Codec
NewCustomCodecWithErrorMapper returns a new JSON Codec based on the passed encoder selector and also accepts an errorMapper function. The errorMapper function will be called if the Service implementation returns an error, with that error as a param, replacing it by the value returned by this function. This function is intended to decouple your service implementation from the codec itself, making possible to return abstract errors in your service, and then mapping them here to the JSON-RPC error codes.
func (*Codec) NewRequest ¶
NewRequest returns a CodecRequest.
type CodecRequest ¶
type CodecRequest struct {
// contains filtered or unexported fields
}
CodecRequest decodes and encodes a single request.
func (*CodecRequest) Method ¶
func (c *CodecRequest) Method() (string, error)
Method returns the RPC method for the current request.
The method uses a dotted notation as in "Service.Method".
func (*CodecRequest) ReadRequest ¶
func (c *CodecRequest) ReadRequest(args interface{}) error
ReadRequest fills the request object for the RPC method.
ReadRequest parses request parameters in two supported forms in accordance with http://www.jsonrpc.org/specification#parameter_structures
by-position: params MUST be an Array, containing the values in the Server expected order.
by-name: params MUST be an Object, with member names that match the Server expected parameter names. The absence of expected names MAY result in an error being generated. The names MUST match exactly, including case, to the method's expected parameters.
func (*CodecRequest) WriteError ¶
func (c *CodecRequest) WriteError(w http.ResponseWriter, _ int, err error)
WriteError encodes the error and writes it to the ResponseWriter.
func (*CodecRequest) WriteResponse ¶
func (c *CodecRequest) WriteResponse(w http.ResponseWriter, reply interface{})
WriteResponse encodes the response and writes it to the ResponseWriter.