Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClientNotExist = errors.New("client not exist")
var ErrInvalidID = errors.New("invalid id")
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // SetID sets the ID of the client. SetID(id ID) // IsRunning returns true if the client is running/alive. IsRunning() bool // EnqueueMessage enqueues a message to be sent to the client. EnqueueMessage(message *messages.GlideMessage) error // Exit the client and close the connection. Exit() // Run starts the client message handling loop and blocks until the client. Run() // GetInfo returns the client's information. GetInfo() Info // Logged returns true if the client is logged in. Logged() bool }
Client is a client connection abstraction.
type Gateway ¶
type Gateway interface { // SetClientID sets the client id with the new id. SetClientID(old ID, new_ ID) error // ExitClient exits the client with the given id. ExitClient(id ID) error // IsOnline returns true if the client is online. IsOnline(id ID) bool Interface }
Gateway is the basic and common interface for all gate implementations. As the basic gate, it is used to provide a common gate interface for other modules to interact with the gate.
type ID ¶
type ID string
ID is used to identify the client, the ID is consist of multiple parts, some of them are optional. The ID is constructed by concatenating the parts with a '_' separator, and the parts are:
- The gateway id (optional): the string id of the gateway that the client is connected to.
- The client id (required): the int64 or string id of the client, it is unique for each client.
- if the client is temporary, this id is a string generated by the gateway, otherwise it is an int64.
- The client type (optional): the int type of the client, like 'web', 'mobile', 'desktop', etc.
func NewID2 ¶
func NewID2(uid interface{}) ID
NewID2 creates a new ID from the given user id, use the empty gateway id and the empty client type.
func (*ID) Device ¶
Device returns the device type of the client, if the client device type is not set, it returns -1.
type Info ¶
type Info struct { // ID is the unique identifier for the client. ID ID // AliveAt is the time the client was last seen. AliveAt int64 // ConnectionAt is the time the client was connected. ConnectionAt int64 // Gateway is the name of the gateway the client is connected to. Gateway string // CliAddr is the address of the client. CliAddr string }
Info represents a client's information.
type Interface ¶
type Interface interface { // EnqueueMessage enqueues the message to the client with the given id. EnqueueMessage(id ID, message *messages.GlideMessage) error }
type MessageHandler ¶
type MessageHandler func(cliInfo *Info, message *messages.GlideMessage)
MessageHandler used to handle messages from the gate.
type Server ¶
type Server interface { Gateway // SetMessageHandler sets the client message handler. SetMessageHandler(h MessageHandler) // HandleConnection handles the new client connection and returns the random and temporary id set for the connection. HandleConnection(c conn.Connection) ID Run() error }
Server is the interface for the gateway server, which is used to handle and manager client connections.