Documentation ¶
Index ¶
- Constants
- func DefaultHTTPClient(remoteAddr string) (*http.Client, error)
- type Caller
- type Client
- type HTTPClient
- type RequestBatch
- type URIClient
- type WSClient
- func (c *WSClient) Call(ctx context.Context, method string, params map[string]interface{}) error
- func (c *WSClient) CallWithArrayParams(ctx context.Context, method string, params []interface{}) error
- func (c *WSClient) IsActive() bool
- func (c *WSClient) IsReconnecting() bool
- func (c *WSClient) OnReconnect(cb func())
- func (c *WSClient) Send(ctx context.Context, request rpctypes.RPCRequest) error
- func (c *WSClient) Start() error
- func (c *WSClient) Stop() error
- func (c *WSClient) String() string
- func (c *WSClient) Subscribe(ctx context.Context, query string) error
- func (c *WSClient) Unsubscribe(ctx context.Context, query string) error
- func (c *WSClient) UnsubscribeAll(ctx context.Context) error
- type WSOptions
Constants ¶
const ( // URIClientRequestID in a request ID used by URIClient URIClientRequestID = rpctypes.JSONRPCIntID(-1) )
Variables ¶
This section is empty.
Functions ¶
func DefaultHTTPClient ¶
DefaultHTTPClient is used to create an http client with some default parameters. We overwrite the http.Client.Dial so we can do http over tcp or unix. remoteAddr should be fully featured (eg. with tcp:// or unix://). An error will be returned in case of invalid remoteAddr.
Types ¶
type Caller ¶
type Caller interface {
Call(ctx context.Context, method string, params map[string]interface{}, result interface{}) (interface{}, error)
}
Caller implementers can facilitate calling the JSON-RPC endpoint.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a JSON-RPC client, which sends POST HTTP requests to the remote server.
Client is safe for concurrent use by multiple goroutines.
func New ¶
New returns a Client pointed at the given address. An error is returned on invalid remote. The function panics when remote is nil.
func NewWithHTTPClient ¶
NewWithHTTPClient returns a Client pointed at the given address using a custom http client. An error is returned on invalid remote. The function panics when client is nil.
func (*Client) Call ¶
func (c *Client) Call( ctx context.Context, method string, params map[string]interface{}, result interface{}, ) (interface{}, error)
Call issues a POST HTTP request. Requests are JSON encoded. Content-Type: application/json.
func (*Client) NewRequestBatch ¶
func (c *Client) NewRequestBatch() *RequestBatch
NewRequestBatch starts a batch of requests for this client.
type HTTPClient ¶
type HTTPClient interface { // Call calls the given method with the params and returns a result. Call(ctx context.Context, method string, params map[string]interface{}, result interface{}) (interface{}, error) }
HTTPClient is a common interface for JSON-RPC HTTP clients.
type RequestBatch ¶
type RequestBatch struct {
// contains filtered or unexported fields
}
RequestBatch allows us to buffer multiple request/response structures into a single batch request. Note that this batch acts like a FIFO queue, and is thread-safe.
func (*RequestBatch) Call ¶
func (b *RequestBatch) Call( _ context.Context, method string, params map[string]interface{}, result interface{}, ) (interface{}, error)
Call enqueues a request to call the given RPC method with the specified parameters, in the same way that the `Client.Call` function would.
func (*RequestBatch) Clear ¶
func (b *RequestBatch) Clear() int
Clear empties out the request batch.
func (*RequestBatch) Count ¶
func (b *RequestBatch) Count() int
Count returns the number of enqueued requests waiting to be sent.
func (*RequestBatch) Send ¶
func (b *RequestBatch) Send(ctx context.Context) ([]interface{}, error)
Send will attempt to send the current batch of enqueued requests, and then will clear out the requests once done. On success, this returns the deserialized list of results from each of the enqueued requests.
type URIClient ¶
type URIClient struct {
// contains filtered or unexported fields
}
URIClient is a JSON-RPC client, which sends POST form HTTP requests to the remote server.
URIClient is safe for concurrent use by multiple goroutines.
type WSClient ¶
type WSClient struct { *tmclient.RunState Address string // IP:PORT or /path/to/socket Endpoint string // /websocket/url/endpoint Dialer func(string, string) (net.Conn, error) // Single user facing channel to read RPCResponses from, closed only when the // client is being stopped. ResponsesCh chan rpctypes.RPCResponse // Time between sending a ping and receiving a pong. See // https://godoc.org/github.com/rcrowley/go-metrics#Timer. PingPongLatencyTimer metrics.Timer // contains filtered or unexported fields }
WSClient is a JSON-RPC client, which uses WebSocket for communication with the remote server.
WSClient is safe for concurrent use by multiple goroutines.
func NewWS ¶
NewWS returns a new client. The endpoint argument must begin with a `/`. An error is returned on invalid remote. It uses DefaultWSOptions.
func NewWSWithOptions ¶ added in v0.35.0
NewWSWithOptions allows you to provide custom WSOptions.
func (*WSClient) Call ¶
Call enqueues a call request onto the Send queue. Requests are JSON encoded.
func (*WSClient) CallWithArrayParams ¶
func (c *WSClient) CallWithArrayParams(ctx context.Context, method string, params []interface{}) error
CallWithArrayParams enqueues a call request onto the Send queue. Params are in a form of array (e.g. []interface{}{"abcd"}). Requests are JSON encoded.
func (*WSClient) IsReconnecting ¶
IsReconnecting returns true if the client is reconnecting right now.
func (*WSClient) OnReconnect ¶ added in v0.35.0
func (c *WSClient) OnReconnect(cb func())
OnReconnect sets the callback, which will be called every time after successful reconnect. Could only be set before Start.
func (*WSClient) Send ¶
Send the given RPC request to the server. Results will be available on ResponsesCh, errors, if any, on ErrorsCh. Will block until send succeeds or ctx.Done is closed.
func (*WSClient) Start ¶ added in v0.35.0
Start dials the specified service address and starts the I/O routines.
func (*WSClient) Subscribe ¶
Subscribe to a query. Note the server must have a "subscribe" route defined.
func (*WSClient) Unsubscribe ¶
Unsubscribe from a query. Note the server must have a "unsubscribe" route defined.
type WSOptions ¶ added in v0.35.0
type WSOptions struct { MaxReconnectAttempts uint // maximum attempts to reconnect ReadWait time.Duration // deadline for any read op WriteWait time.Duration // deadline for any write op PingPeriod time.Duration // frequency with which pings are sent }
WSOptions for WSClient.
func DefaultWSOptions ¶ added in v0.35.0
func DefaultWSOptions() WSOptions
DefaultWSOptions returns default WS options.