50 lines
1015 B
Go
50 lines
1015 B
Go
package messages
|
||
|
||
import (
|
||
"encoding/json"
|
||
|
||
"github.com/spf13/viper"
|
||
)
|
||
|
||
// 事件
|
||
type Event struct {
|
||
MessageId string
|
||
Tag EventTag // 消息标签:EventTagUser=用户
|
||
Flag EventFlag // 消息标签:EventFlagCreate=创建 EventFlagUpdate=更新
|
||
EventId string // 事件ID
|
||
EventContent any // 事件内容
|
||
}
|
||
|
||
type EventTag string
|
||
|
||
const (
|
||
EventTagUser EventTag = "user"
|
||
EventTagRoomInto EventTag = "into_room"
|
||
EventTagMessage EventTag = "message"
|
||
)
|
||
|
||
func TagIndex(key string) string {
|
||
switch key {
|
||
case string(EventTagUser):
|
||
return viper.GetString("es.default.indexUser")
|
||
case string(EventTagMessage):
|
||
return viper.GetString("es.default.indexMessage")
|
||
default:
|
||
return ""
|
||
}
|
||
}
|
||
|
||
type EventFlag string
|
||
|
||
const (
|
||
EventFlagSave EventFlag = "save"
|
||
EventFlagCreate EventFlag = "create"
|
||
EventFlagUpdate EventFlag = "update"
|
||
EventFlagDelete EventFlag = "delete"
|
||
)
|
||
|
||
func (message *Event) ToJson() string {
|
||
b, _ := json.Marshal(message)
|
||
return string(b)
|
||
}
|