Documentation ¶
Index ¶
- type Client
- func (clt *Client) Close()
- func (clt *Client) CloseSession() error
- func (clt *Client) Connect() (err error)
- func (clt *Client) IsConnected() bool
- func (clt *Client) PendingRequests() int
- func (clt *Client) Request(name string, payload webwire.Payload) (webwire.Payload, *webwire.Error)
- func (clt *Client) RestoreSession(sessionKey []byte) error
- func (clt *Client) Session() webwire.Session
- func (clt *Client) Signal(name string, payload webwire.Payload) error
- func (clt *Client) TimedRequest(name string, payload webwire.Payload, timeout time.Duration) (webwire.Payload, *webwire.Error)
- type Hooks
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an instance of one of the servers clients
func NewClient ¶
func NewClient( serverAddr string, hooks Hooks, defaultTimeout time.Duration, warningLogWriter io.Writer, errorLogWriter io.Writer, ) Client
NewClient creates a new disconnected client instance.
func (*Client) Close ¶
func (clt *Client) Close()
Close gracefully closes the connection. Does nothing if the client isn't connected
func (*Client) CloseSession ¶
CloseSession closes the currently active session and synchronizes the closure to the server if connected. If the client is not connected then the synchronization is skipped. Does nothing if there's no active session
func (*Client) Connect ¶
Connect connects the client to the configured server and returns an error in case of a connection failure. Automatically tries to restore the previous session
func (*Client) IsConnected ¶
IsConnected returns true if the client is connected to the server, otherwise false is returned
func (*Client) PendingRequests ¶
PendingRequests returns the number of currently pending requests
func (*Client) Request ¶
func (clt *Client) Request( name string, payload webwire.Payload, ) (webwire.Payload, *webwire.Error)
Request sends a request containing the given payload to the server and asynchronously returns the servers response blocking the calling goroutine. Returns an error if the request failed for some reason
func (*Client) RestoreSession ¶
RestoreSession tries to restore the previously opened session. Fails if a session is currently already active
func (*Client) TimedRequest ¶
func (clt *Client) TimedRequest( name string, payload webwire.Payload, timeout time.Duration, ) (webwire.Payload, *webwire.Error)
TimedRequest sends a request containing the given payload to the server and asynchronously returns the servers reply blocking the calling goroutine. Returns an error if the given timeout was exceeded awaiting the response or another failure occurred
type Hooks ¶
type Hooks struct { // OnServerSignal is an optional callback. // It's invoked when the webwire client receives a signal from the server OnServerSignal func(payload webwire.Payload) // OnSessionCreated is an optional callback. // It's invoked when the webwire client receives a new session OnSessionCreated func(*webwire.Session) // OnSessionClosed is an optional callback. // It's invoked when the clients session was closed // either by the server or by himself OnSessionClosed func() }
Hooks represents all callback hook functions
func (*Hooks) SetDefaults ¶
func (hooks *Hooks) SetDefaults()
SetDefaults sets undefined required hooks