client

package
v0.0.1-20230117-0003 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConnectionFailedToHost = define.Err(300, "connection failed to host")
View Source
var NoConnectionsDefined = define.Err(400, "no connections have being defined")
View Source
var ReaderError = define.Err(200, "reader error")
View Source
var WriterError = define.Err(100, "writer error")

Functions

This section is empty.

Types

type Client

type Client struct {

	// RequestHeader -> can be configured directly
	RequestHeader http.Header

	// This is the Logger of the websocket client, we make it public, for easier interaction!
	Logger *model.Logger

	//Objects
	WSClient     *websocket.Conn // This is the Gorilla Web Socket Client
	HttpResponse *http.Response  // This is the response from the server!
	// contains filtered or unexported fields
}

func New

func New(
	ctx context.Context,
	config config.Config,
) (*Client, error)

func (*Client) Connect

func (c *Client) Connect()

Connect -> connect to the host

func (*Client) Disconnect

func (c *Client) Disconnect()

Disconnect -> It will send the disconnect packet, but it will not wait for it! Forcefully Stops the connection! This function can also be called by the user! to terminate the connection!

func (*Client) DisconnectGracefully

func (c *Client) DisconnectGracefully(code uint16, message string)

DisconnectGracefully -> It will send the disconnect packet, but it will wait until it receives confirmation, and if it doesn't receives it, it will be refer to the timeout and other params configured on the client after everything has passed, it will disconnect

func (*Client) GetConnectedTo

func (c *Client) GetConnectedTo() int

GetConnectedTo -> Where has being connected to

func (*Client) GetConnectingTo

func (c *Client) GetConnectingTo() int

GetConnectingTo -> Where it's trying to connect to!

func (*Client) GetConnection

func (c *Client) GetConnection(connectionNr int) *connection.Connection

func (*Client) GetConnections

func (c *Client) GetConnections() []*connection.Connection

func (*Client) GetLatency

func (c *Client) GetLatency()

func (*Client) HasOnConnectFailedAll

func (c *Client) HasOnConnectFailedAll(name string) bool

func (*Client) HasOnConnectSuccess

func (c *Client) HasOnConnectSuccess(name string) bool

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected -> If is connected right now!

func (*Client) IsConnecting

func (c *Client) IsConnecting() bool

IsConnecting -> If is connecting right now!

func (*Client) LDebug

func (c *Client) LDebug() *zerolog.Event

LDebug -> 0

func (*Client) LDebugF

func (c *Client) LDebugF(functionName string) *zerolog.Event

LDebugF -> when you need specifically to indicate in what function the logging is happening

func (*Client) LError

func (c *Client) LError() *zerolog.Event

LError -> 3

func (*Client) LErrorF

func (c *Client) LErrorF(functionName string) *zerolog.Event

LErrorF -> when you need specifically to indicate in what function the logging is happening

func (*Client) LEvent

func (c *Client) LEvent(eventType string, eventName string, beforeMsg func(event *zerolog.Event))

func (*Client) LEventCustom

func (c *Client) LEventCustom(eventType string, eventName string) *zerolog.Event

func (*Client) LEventF

func (c *Client) LEventF(eventType string, eventName string, functionName string) *zerolog.Event

func (*Client) LFatal

func (c *Client) LFatal() *zerolog.Event

LFatal -> 4

func (*Client) LInfo

func (c *Client) LInfo() *zerolog.Event

LInfo -> 1

func (*Client) LInfoF

func (c *Client) LInfoF(functionName string) *zerolog.Event

LInfoF -> when you need specifically to indicate in what function the logging is happening

func (*Client) LPanic

func (c *Client) LPanic() *zerolog.Event

LPanic -> 5

func (*Client) LWarn

func (c *Client) LWarn() *zerolog.Event

LWarn -> 2

func (*Client) LWarnF

func (c *Client) LWarnF(functionName string) *zerolog.Event

LWarnF -> when you need specifically to indicate in what function the logging is happening

func (*Client) OnBeforeConnectToServer

func (c *Client) OnBeforeConnectToServer(name string, callback OnBeforeConnectToServer) bool

func (*Client) OnBeforeConnectToServerRemove

func (c *Client) OnBeforeConnectToServerRemove(name string)

func (*Client) OnBeforeDisconnect

func (c *Client) OnBeforeDisconnect(name string, callback OnBeforeDisconnect) bool

func (*Client) OnBeforeDisconnectRemove

func (c *Client) OnBeforeDisconnectRemove(name string)

func (*Client) OnBinary

func (c *Client) OnBinary(name string, callback OnBinary) bool

func (*Client) OnBinaryRemove

func (c *Client) OnBinaryRemove(name string)

func (*Client) OnConnect

func (c *Client) OnConnect(name string, callback OnConnect) bool

func (*Client) OnConnectError

func (c *Client) OnConnectError(name string, callback OnConnectError) bool

func (*Client) OnConnectErrorRemove

func (c *Client) OnConnectErrorRemove(name string)

func (*Client) OnConnectFailed

func (c *Client) OnConnectFailed(name string, callback OnConnectFailed) bool

func (*Client) OnConnectFailedAll

func (c *Client) OnConnectFailedAll(name string, callback OnConnectFailedAll) bool

func (*Client) OnConnectFailedAllRemove

func (c *Client) OnConnectFailedAllRemove(name string)

func (*Client) OnConnectFailedRemove

func (c *Client) OnConnectFailedRemove(name string)

func (*Client) OnConnectRemove

func (c *Client) OnConnectRemove(name string)

func (*Client) OnConnectSuccess

func (c *Client) OnConnectSuccess(name string, callback OnConnectSuccess) bool

func (*Client) OnConnectSuccessRemove

func (c *Client) OnConnectSuccessRemove(name string)

func (*Client) OnDisconnect

func (c *Client) OnDisconnect(name string, callback OnDisconnect) bool

func (*Client) OnDisconnectRemove

func (c *Client) OnDisconnectRemove(name string)

func (*Client) OnError

func (c *Client) OnError(name string, callback OnError) bool

func (*Client) OnErrorRemove

func (c *Client) OnErrorRemove(name string)

func (*Client) OnLinkDisconnect

func (c *Client) OnLinkDisconnect(name string, callback OnLinkDisconnect) bool

func (*Client) OnLinkDisconnectRemove

func (c *Client) OnLinkDisconnectRemove(name string)

func (*Client) OnMessage

func (c *Client) OnMessage(name string, callback OnReceive) bool

OnMessage analog to OnReceive

func (*Client) OnMessageRemove

func (c *Client) OnMessageRemove(name string)

OnMessageRemove analog to OnReceiveRemove

func (*Client) OnReadError

func (c *Client) OnReadError(name string, callback OnReadError) bool

func (*Client) OnReadErrorRemove

func (c *Client) OnReadErrorRemove(name string)

func (*Client) OnReceive

func (c *Client) OnReceive(name string, callback OnReceive) bool

func (*Client) OnReceiveRemove

func (c *Client) OnReceiveRemove(name string)

func (*Client) OnReconnectFailed

func (c *Client) OnReconnectFailed(name string, callback OnReconnectFailed) bool

func (*Client) OnReconnectFailedRemove

func (c *Client) OnReconnectFailedRemove(name string)

func (*Client) OnReconnected

func (c *Client) OnReconnected(name string, callback OnReconnected) bool

func (*Client) OnReconnectedRemove

func (c *Client) OnReconnectedRemove(name string)

func (*Client) OnReconnecting

func (c *Client) OnReconnecting(name string, callback OnReconnecting) bool

func (*Client) OnReconnectingRemove

func (c *Client) OnReconnectingRemove(name string)

func (*Client) OnSend

func (c *Client) OnSend(name string, callback OnSend) bool

func (*Client) OnSendError

func (c *Client) OnSendError(name string, callback OnSendError) bool

func (*Client) OnSendErrorRemove

func (c *Client) OnSendErrorRemove(name string)

func (*Client) OnSendRemove

func (c *Client) OnSendRemove(name string)

func (*Client) OnStopConnectingFinish

func (c *Client) OnStopConnectingFinish(name string, callback OnStopConnectingFinish) bool

func (*Client) OnStopConnectingFinishRemove

func (c *Client) OnStopConnectingFinishRemove(name string)

func (*Client) OnTerminate

func (c *Client) OnTerminate(name string, callback OnTerminate) bool

func (*Client) OnTerminateRemove

func (c *Client) OnTerminateRemove(name string)

func (*Client) OnText

func (c *Client) OnText(name string, callback OnText) bool

func (*Client) OnTextRemove

func (c *Client) OnTextRemove(name string)

func (*Client) Reconnect

func (c *Client) Reconnect()

Reconnect -> it's initiating again the connection process but calling and other callbacks before it... The user can also call this function if handling manually or from other place this process! We have created this function to delimit the connect with reconnect as events, and for the user to know what's happened, and of course for easier understanding!

func (*Client) RemoveOnConnectSuccess

func (c *Client) RemoveOnConnectSuccess(name string)

func (*Client) SendBinary

func (c *Client) SendBinary()

func (*Client) SendJSON

func (c *Client) SendJSON(message interface{}, onJsonError OnJsonError) *Client

func (*Client) SendText

func (c *Client) SendText(message string) *Client

func (*Client) StopConnecting

func (c *Client) StopConnecting()

StopConnecting -> Simply stop connecting

func (*Client) WriteBinary

func (c *Client) WriteBinary()

func (*Client) WriteJSON

func (c *Client) WriteJSON(message interface{}, onJsonError OnJsonError) *Client

WriteJSON - It sends Any structure to the client encoded as JSON!

func (*Client) WriteText

func (c *Client) WriteText(message string) *Client

type OnBeforeConnectToServer

type OnBeforeConnectToServer func()

OnBeforeConnectToServer -> it's being called before each connection call

type OnBeforeDisconnect

type OnBeforeDisconnect func()

type OnBinary

type OnBinary func(recvMessage *server.ReceivedMessage, c *Client)

OnBinary -> when we receive a binary message

type OnConnect

type OnConnect func()

type OnConnectError

type OnConnectError func(error)

OnConnectError -> it's being called when connection has failed to be initiated

type OnConnectErrorResponse

type OnConnectErrorResponse struct {
	// Other details
	MaxRetries uint16 // how many retries will be
	RetryNr    uint16 // the attempt
	// Error Details
	MainError     error
	OriginalError error
	// Connection Details
	ConnectionNr uint16
	Connection   *connection.Connection
}

OnConnectErrorResponse -> it's a response structure for OnConnectFailed

type OnConnectFailed

type OnConnectFailed func(OnConnectErrorResponse)

OnConnectFailed -> It's being called each time when a connection has failed to connect

type OnConnectFailedAll

type OnConnectFailedAll func()

OnConnectFailedAll -> it's being called When all connections have failed to connect!

type OnConnectSuccess

type OnConnectSuccess func(connNr int, connection *connection.Connection)

OnConnectSuccess -> it's being called when the client has being connected successfully to the host

type OnDisconnect

type OnDisconnect func()

type OnError

type OnError func()

type OnJsonError

type OnJsonError func(err error, message interface{})

type OnLinkDisconnect

type OnLinkDisconnect func(connNr int, connection *connection.Connection)

OnLinkDisconnect -> When we have lost connection for a specific connection

type OnReadError

type OnReadError func(error)

type OnReceive

type OnReceive func(recvMessage *server.ReceivedMessage, c *Client)

OnReceive -> when we receive any message (text or binary)

type OnReconnectFailed

type OnReconnectFailed func()

OnReconnectFailed -> When reconnection has totally failed and it has stopped... Usually if reconnect max retries has being set to -1 meaning infinite... this event will not occur!

type OnReconnected

type OnReconnected func(connNr int, connection *connection.Connection)

OnReconnected -> it's being called when reconnection has being called, and the client has successfully connected to the host

type OnReconnecting

type OnReconnecting func()

OnReconnecting -> it's being called when reconnect function it's being called!

type OnSend

type OnSend func()

type OnSendError

type OnSendError func()

type OnStopConnectingFinish

type OnStopConnectingFinish func()

OnStopConnectingFinish -> it's being used when stopConnecting function it's being called! And when the process of connecting is stopped and finished, this event it's being called

type OnTerminate

type OnTerminate func()

OnTerminate -> it's being called when connection has being totally terminated or finalized

type OnText

type OnText func(recvMessage *server.ReceivedMessage, c *Client)

OnText -> when we receive a text message

Jump to

Keyboard shortcuts

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