psclient

package
v4.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2019 License: ISC Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeMsg

func DecodeMsg(msg *pstypes.WebSocketMessage) (interface{}, error)

DecodeMsg attempts to decode the Message content of the given WebSocketMessage based on its EventId. The type contained in the returned interface{} depends on the EventId.

func DecodeMsgInt

func DecodeMsgInt(msg *pstypes.WebSocketMessage) (int, error)

DecodeMsgInt attempts to decode the Message content of the given WebSocketMessage as an int.

func DecodeMsgMempool

func DecodeMsgMempool(msg *pstypes.WebSocketMessage) (*exptypes.MempoolShort, error)

DecodeMsgMempool attempts to decode the Message content of the given WebSocketMessage as a mempool message (*exptypes.MempoolShort).

func DecodeMsgNewAddressTx

func DecodeMsgNewAddressTx(msg *pstypes.WebSocketMessage) (*pstypes.AddressMessage, error)

DecodeMsgNewAddressTx attempts to decode the Message content of the given WebSocketMessage as an address message (*DecodeMsgNewAddressTx).

func DecodeMsgNewBlock

func DecodeMsgNewBlock(msg *pstypes.WebSocketMessage) (*exptypes.WebsocketBlock, error)

DecodeMsgNewBlock attempts to decode the Message content of the given WebSocketMessage as a newblock message (*exptypes.WebsocketBlock).

func DecodeMsgPing

func DecodeMsgPing(msg *pstypes.WebSocketMessage) (int, error)

DecodeMsgPing attempts to decode the Message content of the given WebSocketMessage ping response message (int).

func DecodeMsgString

func DecodeMsgString(msg *pstypes.WebSocketMessage) (string, error)

DecodeMsgString attempts to decode the Message content of the given WebSocketMessage as a string.

func DecodeMsgTxList

func DecodeMsgTxList(msg *pstypes.WebSocketMessage) (*pstypes.TxList, error)

DecodeMsgTxList attempts to decode the Message content of the given WebSocketMessage as a newtxs message (*pstypes.TxList).

func DecodeResponseMsg

func DecodeResponseMsg(msg *pstypes.WebSocketMessage) (*pstypes.ResponseMessage, error)

DecodeResponseMsg attempts to decode the Message content of the given WebSocketMessage as a request response message (string).

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

func Version

func Version() semver.Semver

Version indicates the semantic version of the pubsub module, to which the psclient belongs.

Types

type Client

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

Client wraps a *websocket.Conn.

func New

func New(url string, ctx context.Context, opts *Opts) (*Client, error)

New creates a new Client from a URL.

func NewFromConn

func NewFromConn(ws *websocket.Conn, ctx context.Context, opts *Opts) *Client

NewFromConn creates a new Client from a *websocket.Conn.

func (*Client) Ping

func (c *Client) Ping() error

Ping sends a ping to the server. There is no response.

func (*Client) Receive

func (c *Client) Receive() <-chan *ClientMessage

Receive gets a receive-only *ClientMessage channel, through which all messages from the server to the client should be received.

func (*Client) ServerVersion

func (c *Client) ServerVersion() (*pstypes.Ver, error)

ServerVersion sends a server version query, and returns the response.

func (*Client) Stop

func (c *Client) Stop()

Stop shutsdown the Client. If the websocket connection was created during Client construction, it is is shutdown too.

func (*Client) Subscribe

func (c *Client) Subscribe(event string) (*pstypes.ResponseMessage, error)

Subscribe sends a subscribe type WebSocketMessage for the given event name after validating it. The response is returned.

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(event string) (*pstypes.ResponseMessage, error)

Unsubscribe sends an unsubscribe type WebSocketMessage for the given event name after validating it. The response is returned.

type ClientMessage

type ClientMessage struct {
	EventId string
	Message interface{}
}

ClientMessage represents a message for a client connection. The (*Client).Receive method provides a channel such messages from the server.

type Opts

type Opts struct {
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

Opts defines the psclient Client options.

Jump to

Keyboard shortcuts

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