-
Notifications
You must be signed in to change notification settings - Fork 627
/
Copy pathmsg_model.go
60 lines (50 loc) · 1.54 KB
/
msg_model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Package models 数据模型
package models
import "github.com/link1st/gowebsocket/v2/common"
const (
// MessageTypeText 文本类型消息
MessageTypeText = "text"
// MessageCmdMsg 文本类型消息
MessageCmdMsg = "msg"
// MessageCmdEnter 用户进入类型消息
MessageCmdEnter = "enter"
// MessageCmdExit 用户退出类型消息
MessageCmdExit = "exit"
)
// Message 消息的定义
type Message struct {
Target string `json:"target"` // 目标
Type string `json:"type"` // 消息类型 text/img/
Msg string `json:"msg"` // 消息内容
From string `json:"from"` // 发送者
}
// NewMsg 创建新的消息
func NewMsg(from string, Msg string) (message *Message) {
message = &Message{
Type: MessageTypeText,
From: from,
Msg: Msg,
}
return
}
func getTextMsgData(cmd, uuID, msgID, message string) string {
textMsg := NewMsg(uuID, message)
head := NewResponseHead(msgID, cmd, common.OK, "Ok", textMsg)
return head.String()
}
// GetMsgData 文本消息
func GetMsgData(uuID, msgID, cmd, message string) string {
return getTextMsgData(cmd, uuID, msgID, message)
}
// GetTextMsgData 文本消息
func GetTextMsgData(uuID, msgID, message string) string {
return getTextMsgData("msg", uuID, msgID, message)
}
// GetTextMsgDataEnter 用户进入消息
func GetTextMsgDataEnter(uuID, msgID, message string) string {
return getTextMsgData("enter", uuID, msgID, message)
}
// GetTextMsgDataExit 用户退出消息
func GetTextMsgDataExit(uuID, msgID, message string) string {
return getTextMsgData("exit", uuID, msgID, message)
}