Documentation ¶
Index ¶
- Constants
- Variables
- func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec
- func NewJSONCodec(conn io.ReadWriteCloser, srv *rpc.Server) rpc.ServerCodec
- func ServeConn(conn io.ReadWriteCloser)
- type API
- type BatchArg
- type Client
- type Error
- type HTTPServer
- type JSONRPC2
- type Server
- type WebsocketServerConn
- type WsRPCServer
Constants ¶
const MetadataAPI = "rpc"
MetadataAPI is a default service for RegisterName.
Variables ¶
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 ¶
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 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.
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 ServerError ¶
ServerError convert errors returned by Client.Call() into Error. User should check for rpc.ErrShutdown and io.ErrUnexpectedEOF before calling ServerError.
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.
type WebsocketServerConn ¶
WebsocketServerConn represents a websocket server connection
func (*WebsocketServerConn) Close ¶
func (wc *WebsocketServerConn) Close() (err error)
Close represents close the 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.