Files
mayfly-go/server/internal/msg/application/dto/sys_msg.go

59 lines
1.4 KiB
Go
Raw Normal View History

2023-10-10 17:39:46 +08:00
package dto
2023-10-20 21:31:46 +08:00
import "mayfly-go/pkg/utils/anyx"
2023-10-10 17:39:46 +08:00
// ************** 系统消息 **************
const SuccessSysMsgType = 1
const ErrorSysMsgType = 0
const InfoSysMsgType = 2
const InfoTypeSqlExecProgress = 22
2023-10-10 17:39:46 +08:00
// websocket消息
type SysMsg struct {
Type int `json:"type"` // 消息类型
Category string `json:"category"` // 消息类别
2023-10-10 17:39:46 +08:00
Title string `json:"title"` // 消息标题
Msg string `json:"msg"` // 消息内容
ClientId string
2023-10-10 17:39:46 +08:00
}
func (sm *SysMsg) WithTitle(title string) *SysMsg {
sm.Title = title
return sm
}
func (sm *SysMsg) WithCategory(category string) *SysMsg {
2023-10-10 17:39:46 +08:00
sm.Category = category
return sm
}
func (sm *SysMsg) WithMsg(msg any) *SysMsg {
2023-10-20 21:31:46 +08:00
sm.Msg = anyx.ToString(msg)
2023-10-10 17:39:46 +08:00
return sm
}
func (sm *SysMsg) WithClientId(clientId string) *SysMsg {
sm.ClientId = clientId
return sm
}
2023-10-10 17:39:46 +08:00
// 普通消息
func InfoSysMsg(title string, msg any) *SysMsg {
2023-10-20 21:31:46 +08:00
return &SysMsg{Type: InfoSysMsgType, Title: title, Msg: anyx.ToString(msg)}
2023-10-10 17:39:46 +08:00
}
func InfoSqlProgressMsg(title string, msg any) *SysMsg {
return &SysMsg{Type: InfoTypeSqlExecProgress, Title: title, Msg: anyx.ToString(msg)}
}
2023-10-10 17:39:46 +08:00
// 成功消息
func SuccessSysMsg(title string, msg any) *SysMsg {
2023-10-20 21:31:46 +08:00
return &SysMsg{Type: SuccessSysMsgType, Title: title, Msg: anyx.ToString(msg)}
2023-10-10 17:39:46 +08:00
}
// 错误消息
func ErrSysMsg(title string, msg any) *SysMsg {
2023-10-20 21:31:46 +08:00
return &SysMsg{Type: ErrorSysMsgType, Title: title, Msg: anyx.ToString(msg)}
2023-10-10 17:39:46 +08:00
}