54 lines
999 B
Go
54 lines
999 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type ChatMessage struct {
|
|
UserID string
|
|
UserName string
|
|
CreateTx time.Time
|
|
Type string
|
|
Text string
|
|
}
|
|
|
|
const (
|
|
ChatTypeText = "TEXT" // 对话
|
|
ChatTypeCard = "CARD" // 工具卡片分享
|
|
)
|
|
|
|
func NewTextChatMsg(user *Users, text string) *ChatMessage {
|
|
return &ChatMessage{
|
|
UserID: user.ID,
|
|
UserName: user.Name,
|
|
CreateTx: time.Now(),
|
|
Type: ChatTypeText,
|
|
Text: text,
|
|
}
|
|
}
|
|
|
|
type Message struct {
|
|
Cmd string
|
|
User UserFollows
|
|
ChatMessage ChatMessage
|
|
}
|
|
|
|
//
|
|
//// Value 接口,Value 返回 json value any -> string
|
|
//func (j *Users) Value() (driver.Value, error) {
|
|
// return json.Marshal(j)
|
|
//}
|
|
//
|
|
//// Scan 接口,Scan 将 value 扫描至 Jsonb
|
|
//func (j *Users) Scan(value interface{}) error {
|
|
// bytes, ok := value.([]byte)
|
|
// if !ok {
|
|
// return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
|
|
// }
|
|
// err := json.Unmarshal(bytes, j)
|
|
// if err != nil {
|
|
// return err
|
|
// }
|
|
// return nil
|
|
//}
|