router

package
v0.0.0-...-59da782 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VISITOR   = 0
	NOMALUSER = 1
	MANAGER   = 2
)

Variables

This section is empty.

Functions

func AddUser

func AddUser(u *User)

func AppendChannel

func AppendChannel(key string, value *Channel)

func DeleteChannel

func DeleteChannel(key string)

func GetUserClientNums

func GetUserClientNums() int

func GetUserNums

func GetUserNums() int

func IsUserOnline

func IsUserOnline(userId string) bool

Types

type Channel

type Channel struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Channel struct of room or personal chan dec

func GetChannel

func GetChannel(key string) (*Channel, bool)

func NewChannel

func NewChannel(route string) *Channel

func (*Channel) Broadcast

func (cl *Channel) Broadcast(msg interface{})

func (*Channel) GetRegisterNumber

func (cl *Channel) GetRegisterNumber() int

func (*Channel) Register

func (cl *Channel) Register(userId string, client *Client)

func (*Channel) UnRegister

func (cl *Channel) UnRegister(userId string, client *Client)

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a middleman between the websocket connection and the hub

func NewClient

func NewClient(id, device, uuid string, createTime, loginTime int64, conn Connection, u *User) *Client

func (*Client) Close

func (c *Client) Close(code int, msg string) error

func (*Client) GetCreateTime

func (c *Client) GetCreateTime() int64

func (*Client) GetDevice

func (c *Client) GetDevice() string

func (*Client) GetId

func (c *Client) GetId() string

func (*Client) GetLoginTime

func (c *Client) GetLoginTime() int64

func (*Client) GetUUID

func (c *Client) GetUUID() string

func (*Client) GetUser

func (c *Client) GetUser() *User

func (*Client) Run

func (c *Client) Run() error

func (*Client) Send

func (c *Client) Send(msg interface{})

type Connection

type Connection interface {
	WriteResponse(interface{})
	Args() interface{}
	Start() error
	Close(...interface{}) error
}

type Hub

type Hub struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Hub maintains the set of active clients and broadcasts messages to the clients.

func NewHub

func NewHub() *Hub

func (*Hub) GetAllClients

func (h *Hub) GetAllClients() []*Client

func (*Hub) IsExist

func (h *Hub) IsExist(key *Client) bool

func (*Hub) Run

func (h *Hub) Run()

type User

type User struct {
	sync.RWMutex

	Id    string
	Level int
	// contains filtered or unexported fields
}

User struct

func GetUser

func GetUser(key string) (*User, bool)

func NewUser

func NewUser(userId string, level int) *User

func (*User) AppendClient

func (u *User) AppendClient(c *Client)

func (*User) ClientUnRegister

func (u *User) ClientUnRegister(clientId string, channel *Channel)

func (*User) DeleteClient

func (u *User) DeleteClient(clientId string)

func (*User) GetClient

func (u *User) GetClient(clientId string) (*Client, bool)

func (*User) GetClients

func (u *User) GetClients() map[string]*Client

func (*User) SendToAllClients

func (u *User) SendToAllClients(msg interface{})

func (*User) Subscribe

func (u *User) Subscribe(channel *Channel)

all client regist current channel

func (*User) UnSubscribe

func (u *User) UnSubscribe(channel *Channel)

Jump to

Keyboard shortcuts

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