jsonrpc2

package
v0.0.0-...-6c85081 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package jsonrpc2 implements a JSON-RPC 2.0 ClientCodec and ServerCodec for the net/rpc package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPHandler

func HTTPHandler(srv *rpc.Server) http.Handler

HTTPHandler returns handler for HTTP requests which will execute incoming RPC using srv. If srv is nil then use rpc.DefaultServer.

Specification: http://www.simple-is-better.org/json-rpc/transport_http.html

  • Pipelined Requests/Responses not supported.
  • GET Request not supported.

func NewClientCodec

func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec

NewClientCodec returns a new rpc.ClientCodec using JSON-RPC 2.0 on conn.

func NewServerCodec

func NewServerCodec(conn io.ReadWriteCloser, srv *rpc.Server) rpc.ServerCodec

NewServerCodec returns a new rpc.ServerCodec using JSON-RPC 2.0 on conn, which will use srv to execute batch requests.

If srv is nil then rpc.DefaultServer will be used.

func ServeConn

func ServeConn(conn io.ReadWriteCloser)

ServeConn runs the JSON-RPC 2.0 server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement.

Types

type BatchArg

type BatchArg struct {
	// contains filtered or unexported fields
}

BatchArg is a param for internal RPC JSONRPC2.Batch.

type Client

type Client struct {
	*rpc.Client
	// contains filtered or unexported fields
}

Client represents a JSON RPC 2.0 Client. There may be multiple outstanding Calls associated with a single Client, and a Client may be used by multiple goroutines simultaneously.

It also provides all methods of net/rpc Client.

func Dial

func Dial(network, address string) (*Client, error)

Dial connects to a JSON-RPC 2.0 server at the specified network address.

func NewClient

func NewClient(conn io.ReadWriteCloser) *Client

NewClient returns a new Client to handle requests to the set of services at the other end of the connection.

func NewHTTPClient

func NewHTTPClient(url string) *Client

NewHTTPClient returns a new Client to handle requests to the set of services at the given url.

func (Client) GetUnhandledChannel

func (c Client) GetUnhandledChannel() chan interface{}

func (Client) Notify

func (c Client) Notify(serviceMethod string, args interface{}) error

Notify try to invoke the named function. It return error only in case it wasn't able to send request.

type Error

type Error struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

Error represent JSON-RPC 2.0 "Error object".

func NewError

func NewError(code int, message string) *Error

NewError returns an Error with given code and message.

func ServerError

func ServerError(rpcerr error) *Error

ServerError convert errors returned by Client.Call() into Error. User should check for rpc.ErrShutdown and io.ErrUnexpectedEOF before calling ServerError.

func (*Error) Error

func (e *Error) Error() string

Error returns JSON representation of Error.

type JSONRPC2

type JSONRPC2 struct{}

JSONRPC2 is an internal RPC service used to process batch requests.

func (JSONRPC2) Batch

func (JSONRPC2) Batch(arg BatchArg, replies *[]*json.RawMessage) (err error)

Batch is an internal RPC method used to process batch requests.

Jump to

Keyboard shortcuts

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