Documentation ¶
Index ¶
Constants ¶
View Source
const ( MsgTypeNormal = iota // 普通 用户消息 MsgTypeUserWelcome // 当前用户欢迎消息 MsgTypeUserEnter // 用户进入 MsgTypeUserLeave // 用户离开 MsgTypeError // 错误消息 )
Variables ¶
View Source
var Broadcaster = &broadcaster{ users: make(map[string]*User), enteringChannel: make(chan *User), leavingChannel: make(chan *User), messageChannel: make(chan *Message, global.MessageQueueLen), checkUserChannel: make(chan string), checkUserCanInChannel: make(chan bool), requestUserChannel: make(chan struct{}), usersChannel: make(chan []*User), }
Broadcaster 广播器全局只能有一个,应该使用单例,饿汉式
View Source
var OfflineProcessor = newOfflineProcessor()
Functions ¶
func FilterSensitiveWords ¶
Types ¶
type Message ¶
type Message struct { User *User `json:"user"` // 哪个用户发送的消息 Type int `json:"type"` // 消息类型 Content string `json:"content"` // 消息内容 MsgTime time.Time `json:"msg_time"` // 消息产生时间 ClientSendTime time.Time `json:"client_send_time"` // 客户端发送时间 Ats []string `json:"ats"` // 消息 @ 了谁 }
func NewErrorMessage ¶
func NewUserEnterMessage ¶
func NewUserLeaveMessage ¶
func NewWelcomeMessage ¶
type User ¶
type User struct { UID int `json:"uid"` // 用户id Nickname string `json:"nickname"` // 用户昵称 EnterAt time.Time `json:"enter_at"` // 加入时间 Addr string `json:"addr"` // IP地址 MessageChannel chan *Message `json:"-"` // 消息通道 ps:chan无法转为json输出 Token string `json:"token"` // contains filtered or unexported fields }
func (*User) CloseMessageChannel ¶
func (u *User) CloseMessageChannel()
CloseMessageChannel 避免goroutine泄露
func (*User) ReceiveMessage ¶
ReceiveMessage 接收来自客户端的消息
Click to show internal directories.
Click to hide internal directories.