Documentation ¶
Index ¶
- type Client
- func (clt *Client) Close()
- func (clt *Client) CloseSession() error
- func (clt *Client) Connect() error
- func (clt *Client) PendingRequests() int
- func (clt *Client) Request(name string, payload webwire.Payload) (webwire.Payload, error)
- func (clt *Client) RestoreSession(sessionKey []byte) error
- func (clt *Client) Session() *webwire.Session
- func (clt *Client) SessionInfo(fieldName string) interface{}
- func (clt *Client) Signal(name string, payload webwire.Payload) error
- func (clt *Client) Status() Status
- func (clt *Client) TimedRequest(name string, payload webwire.Payload, timeout time.Duration) (webwire.Payload, error)
- type Implementation
- type Options
- type Status
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( serverAddress string, implementation Implementation, opts Options, ) *Client
NewClient creates a new client instance.
func (*Client) Close ¶
func (clt *Client) Close()
Close gracefully closes the connection and disables the client. A disabled client won't autoconnect until enabled again.
func (*Client) CloseSession ¶
CloseSession disables the currently active session and acknowledges the server if connected. The session will be destroyed if this is it's last connection remaining. 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. Enables autoconnect if it was disabled
func (*Client) PendingRequests ¶
PendingRequests returns the number of currently pending requests
func (*Client) Request ¶
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) Session ¶
Session returns an exact copy of the session object or nil if there's no session currently assigned to this client
func (*Client) SessionInfo ¶
SessionInfo returns a copy of the session info field value in the form of an empty interface to be casted to either concrete type
func (*Client) Status ¶
Status returns the current client status which is either disabled, disconnected or connected. The client is considered disabled when it was manually closed through client.Close, while disconnected is considered a temporary connection loss. A disabled client won't autoconnect until enabled again.
func (*Client) TimedRequest ¶
func (clt *Client) TimedRequest( name string, payload webwire.Payload, timeout time.Duration, ) (webwire.Payload, 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 Implementation ¶
type Implementation interface { // OnDisconnected is invoked when the client is disconnected // from the server for any reason. OnDisconnected() // OnSignal is invoked when the client receives a signal // from the server OnSignal(payload webwire.Payload) // OnSessionCreated is invoked when the client was assigned a new session OnSessionCreated(*webwire.Session) // OnSessionClosed is invoked when the client's session was closed // either by the server or the client itself OnSessionClosed() }
Implementation defines a webwire client implementation interface
type Options ¶
type Options struct { // SessionInfoParser defines the optional session info parser function SessionInfoParser webwire.SessionInfoParser // DefaultRequestTimeout defines the default request timeout duration // used by client.Request and client.RestoreSession DefaultRequestTimeout time.Duration // Autoconnect defines whether the autoconnect feature is to be enabled. // // If autoconnect is enabled then client.Request, client.TimedRequest and // client.RestoreSession won't immediately return a disconnected error // if there's no active connection to the server, // instead they will automatically try to reestablish the connection // before the timeout is triggered and a timeout error is returned. // // Autoconnect is enabled by default Autoconnect webwire.OptionValue // ReconnectionInterval defines the interval at which autoconnect // should retry connection establishment. // If undefined then the default value of 2 seconds is applied ReconnectionInterval time.Duration // WarnLog defines the warn logging output target WarnLog *log.Logger // ErrorLog defines the error logging output target ErrorLog *log.Logger }
Options represents the options used during the creation a new client instance
func (*Options) SetDefaults ¶
func (opts *Options) SetDefaults()
SetDefaults sets default values for undefined required options