first commit
This commit is contained in:
49
pkg/common/messages/event_message.go
Normal file
49
pkg/common/messages/event_message.go
Normal file
@ -0,0 +1,49 @@
|
||||
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 interface{} // 事件内容
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user