Files
servicebase/pkg/common/messages/event_message.go
2025-11-19 14:24:13 +08:00

50 lines
1015 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}