refactor: 系统websocket消息重构

This commit is contained in:
meilin.huang
2023-09-12 20:54:07 +08:00
parent e4e68d02bc
commit 4b973b22a4
10 changed files with 303 additions and 75 deletions

View File

@@ -1,27 +1,46 @@
package ws
const SuccessMsgType = 1
const ErrorMsgType = 0
const InfoMsgType = 2
// 消息类型
type MsgType uint8
const (
JsonMsg MsgType = 1
TextMsg MsgType = 2
BinaryMsg MsgType = 3
)
// 消息信息
type Msg struct {
ToUserId UserId
Data any
Type MsgType // 消息类型
}
// ************** 系统消息 **************
const SuccessSysMsgType = 1
const ErrorSysMsgType = 0
const InfoSysMsgType = 2
// websocket消息
type Msg struct {
Type int `json:"type"` // 消息类型
Title string `json:"title"` // 消息标题
Msg string `json:"msg"` // 消息内容
type SysMsg struct {
Type int `json:"type"` // 消息类型
Title string `json:"title"` // 消息标题
SysMsg string `json:"msg"` // 消息内容
}
// 普通消息
func NewMsg(title, msg string) *Msg {
return &Msg{Type: InfoMsgType, Title: title, Msg: msg}
func NewSysMsg(title, msg string) *SysMsg {
return &SysMsg{Type: InfoSysMsgType, Title: title, SysMsg: msg}
}
// 成功消息
func SuccessMsg(title, msg string) *Msg {
return &Msg{Type: SuccessMsgType, Title: title, Msg: msg}
func SuccessSysMsg(title, msg string) *SysMsg {
return &SysMsg{Type: SuccessSysMsgType, Title: title, SysMsg: msg}
}
// 错误消息
func ErrMsg(title, msg string) *Msg {
return &Msg{Type: ErrorMsgType, Title: title, Msg: msg}
func ErrSysMsg(title, msg string) *SysMsg {
return &SysMsg{Type: ErrorSysMsgType, Title: title, SysMsg: msg}
}