Documentation ¶
Index ¶
- func MaxReconnectAttempts(max int) func(*WSClient)
- func OnReconnect(cb func()) func(*WSClient)
- func PingPeriod(pingPeriod time.Duration) func(*WSClient)
- func ReadWait(readWait time.Duration) func(*WSClient)
- func WriteWait(writeWait time.Duration) func(*WSClient)
- type HTTPClient
- type JSONRPCClient
- 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) Codec() *amino.Codec
- func (c *WSClient) IsActive() bool
- func (c *WSClient) IsReconnecting() bool
- func (c *WSClient) OnStart() error
- func (c *WSClient) OnStop()
- func (c *WSClient) Send(ctx context.Context, request types.RPCRequest) error
- func (c *WSClient) SetCodec(cdc *amino.Codec)
- 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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MaxReconnectAttempts ¶
MaxReconnectAttempts sets the maximum number of reconnect attempts before returning an error. It should only be used in the constructor and is not Goroutine-safe.
func OnReconnect ¶
func OnReconnect(cb func()) func(*WSClient)
OnReconnect sets the callback, which will be called every time after successful reconnect.
func PingPeriod ¶
PingPeriod sets the duration for sending websocket pings. It should only be used in the constructor - not Goroutine-safe.
Types ¶
type HTTPClient ¶
type HTTPClient interface { Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) Codec() *amino.Codec SetCodec(*amino.Codec) }
HTTPClient is a common interface for JSONRPCClient and URIClient.
type JSONRPCClient ¶
type JSONRPCClient struct {
// contains filtered or unexported fields
}
JSONRPCClient takes params as a slice
func NewJSONRPCClient ¶
func NewJSONRPCClient(remote string) *JSONRPCClient
NewJSONRPCClient returns a JSONRPCClient pointed at the given address.
func (*JSONRPCClient) Call ¶
func (c *JSONRPCClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error)
func (*JSONRPCClient) Codec ¶
func (c *JSONRPCClient) Codec() *amino.Codec
func (*JSONRPCClient) SetCodec ¶
func (c *JSONRPCClient) SetCodec(cdc *amino.Codec)
type URIClient ¶
type URIClient struct {
// contains filtered or unexported fields
}
URI takes params as a map
func NewURIClient ¶
type WSClient ¶
type WSClient struct { cmn.BaseService Address string // IP:PORT or /path/to/socket Endpoint string // /websocket/url/endpoint Dialer func(string, string) (net.Conn, error) // Time between sending a ping and receiving a pong. See // https://godoc.org/github.com/rcrowley/go-metrics#Timer. PingPongLatencyTimer metrics.Timer // Single user facing channel to read RPCResponses from, closed only when the client is being stopped. ResponsesCh chan types.RPCResponse // contains filtered or unexported fields }
WSClient is a WebSocket client. The methods of WSClient are safe for use by multiple goroutines.
func NewWSClient ¶
NewWSClient returns a new client. See the commentary on the func(*WSClient) functions for a detailed description of how to configure ping period and pong wait time. The endpoint argument must begin with a `/`.
func (*WSClient) CallWithArrayParams ¶
func (c *WSClient) CallWithArrayParams(ctx context.Context, method string, params []interface{}) error
CallWithArrayParams the given method with params in a form of array. See Send description.
func (*WSClient) IsReconnecting ¶
IsReconnecting returns true if the client is reconnecting right now.
func (*WSClient) OnStart ¶
OnStart implements cmn.Service by dialing a server and creating read and write routines.
func (*WSClient) OnStop ¶ added in v0.10.0
func (c *WSClient) OnStop()
OnStop implements cmn.Service.
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) Stop ¶
Stop overrides cmn.Service#Stop. There is no other way to wait until Quit channel is closed.
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.