rpc

package
v0.0.0-...-9fb4324 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const MetadataAPI = "rpc"

MetadataAPI is a default service for RegisterName.

Variables

View Source
var (
	// ErrInvalidHost will be returned when the host is not in the whitelist
	ErrInvalidHost = errors.New("invalid host name")
)

Functions

func NewClientCodec

func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec

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

func NewJSONCodec

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

NewJSONCodec returns a new rpc.ServerCodec using JSON-RPC on conn.

func ServeConn

func ServeConn(conn io.ReadWriteCloser)

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

Types

type API

type API struct {
	// namespace of service
	Namespace string
	// api version
	Version string
	// the service methods holder
	Service interface{}
	// indication if the methods must be considered safe for public use
	Public bool
}

API is a collection of methods for the RPC interface.

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 NewClientWithCodec

func NewClientWithCodec(codec rpc.ClientCodec) *Client

NewClientWithCodec returns a new Client using the given rpc.ClientCodec.

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 HTTPServer

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

HTTPServer represents a HTTP RPC server

func NewHTTPServer

func NewHTTPServer(whitehosts []string, corsList []string) (*HTTPServer, *hostFilter)

NewHTTPServer returns a new HttpServer and a http handler used by cors

func (*HTTPServer) GetRPCServer

func (server *HTTPServer) GetRPCServer() *rpc.Server

GetRPCServer return rpc server of the HTTPServer

func (*HTTPServer) ServeHTTP

func (server *HTTPServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements an http.Handler that answers RPC requests. Supports POST and CONNECT http method. POST handles requests from the browser CONNECT handles requests form other go rpc.Client

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.

type Server

type Server struct {
	rpc.Server
}

Server represents a RPC server

func NewServer

func NewServer() *Server

NewServer returns a new Server.

type WebsocketServerConn

type WebsocketServerConn struct {
	Ws *websocket.Conn
	// contains filtered or unexported fields
}

WebsocketServerConn represents a websocket server connection

func (*WebsocketServerConn) Close

func (wc *WebsocketServerConn) Close() (err error)

Close represents close the websocket connection.

func (*WebsocketServerConn) Read

func (wc *WebsocketServerConn) Read(p []byte) (n int, err error)

Read represents read data from websocket connection.

func (*WebsocketServerConn) Write

func (wc *WebsocketServerConn) Write(p []byte) (n int, err error)

Write represents write data for websocket connection.

type WsRPCServer

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

WsRPCServer represents a Websocket RPC server

func NewWsRPCServer

func NewWsRPCServer() *WsRPCServer

NewWsRPCServer return a Websocket RPC server

func (*WsRPCServer) GetWsRPCServer

func (server *WsRPCServer) GetWsRPCServer() *rpc.Server

GetWsRPCServer return rpc server of the WsRPCServer

func (*WsRPCServer) ServeWS

func (server *WsRPCServer) ServeWS(w http.ResponseWriter, r *http.Request)

ServeWS runs the JSON-RPC server on a single websocket connection.

Jump to

Keyboard shortcuts

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