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 }
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 string id of the client, it is unique for user.
- if the client is temporary, this id is a string generated by the gateway and start with `tmp`.
- The client type (optional): the int type of the client, like 'web', 'mobile', 'desktop', etc.
func GenTempID ¶ added in v1.1.0
GenTempID generates a temporary ID. ID implementation is a UUID v4, which is generated by random number generator.
func NewID2 ¶
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 "".
func (*ID) Gateway ¶
Gateway returns the gateway id of the client, if not set, it returns an empty string.
func (*ID) SetGateway ¶ added in v1.2.3
SetGateway sets the gateway part of the ID.
type Info ¶
type Info struct { // ID is the unique identifier for the client. ID ID // Version is the version of the client. Version string // 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.