Documentation
¶
Index ¶
- Variables
- func GenerateEventID() uint64
- func GenerateNodeId() string
- func GetMasterNodeId() string
- func GetPluginVerifier(isVerify bool) string
- func GetSelfNodeId() string
- func InitLocalDatabase()
- func Publish(event *IceinuEvent)
- func SetMasterNodeId(masterNodeId string)
- func SetSelfNodeId(selfNodeId string)
- func Subscribe(eventType uint8, summary string, handler EventHandler) string
- func Unsubscribe(eventType uint8, summary string, subID string)
- func UseGlobalPublishMiddleware(middleware PublishMiddleware)
- func UseSubscribeMiddleware(middleware SubscribeMiddleware)
- func UseSummaryPublishMiddleware(summary string, middleware PublishMiddleware)
- func UseTypePublishMiddleware(eventType uint8, middleware PublishMiddleware)
- func VerifyPlugin()
- type AdapterConnectEvent
- type AdapterDisconnectEvent
- type DataCallbackEvent
- type EventBus
- func (bus *EventBus) GetSubscribers(eventType uint8, summary string) []subscription
- func (bus *EventBus) Publish(event *IceinuEvent)
- func (bus *EventBus) Subscribe(eventType uint8, summary string, handler EventHandler) string
- func (bus *EventBus) Unsubscribe(eventType uint8, summary string, subID string)
- func (bus *EventBus) UseGlobalPublishMiddleware(middleware PublishMiddleware)
- func (bus *EventBus) UseSubscribeMiddleware(middleware SubscribeMiddleware)
- func (bus *EventBus) UseSummaryPublishMiddleware(summary string, middleware PublishMiddleware)
- func (bus *EventBus) UseTypePublishMiddleware(eventType uint8, middleware PublishMiddleware)
- type EventHandler
- type IceinuEvent
- func MakeAdapterConnectEvent(adapterType string, model string, userId string, userName string) *IceinuEvent
- func MakeAdapterDisconnectEvent() *IceinuEvent
- func MakeNodeConnectRequestEvent(mode string, adapterModel string, pluginVerifier string) *IceinuEvent
- func MakeNodeConnectedEvent() *IceinuEvent
- func MakeNodeDeactiveEvent() *IceinuEvent
- func MakeNodeDisconnectedEvent() *IceinuEvent
- func MakeNodePushDataEvent(data interface{}) *IceinuEvent
- func MakeNodeReactiveEvent() *IceinuEvent
- func MakeNodeRequestDataEvent(dataType string, key string, query string) *IceinuEvent
- func MakeNodeUserPushEvent(data interface{}) *IceinuEvent
- func MakeRequestNodeDataEvent(dataType string, key string, query string) *IceinuEvent
- func MakeWebsocketHeartbeatEvent() *IceinuEvent
- type IceinuNodeData
- type IceinuPluginList
- type NodeConnectRequestEvent
- type NodeConnectedEvent
- type NodeDeactiveEvent
- type NodeDisconnectedEvent
- type NodePushDataEvent
- type NodeReactiveEvent
- type NodeRequestDataEvent
- type NodeUserPushEvent
- type PublishMiddleware
- type RequestNodeDataEvent
- type SubscribeMiddleware
- type WebSocketHeartbeatEvent
Constants ¶
This section is empty.
Variables ¶
var LocalDatabase *gorm.DB // 本地数据库连接
var MasterNodeId string
var PluginVerifier string
var RemoteDatabase *gorm.DB // 远程数据库连接
var SelfNodeId string
Functions ¶
func GenerateEventID ¶
func GenerateEventID() uint64
GenerateEventID 使用 math/rand 生成随机的 uint64 事件 ID
func GetMasterNodeId ¶
func GetMasterNodeId() string
func GetPluginVerifier ¶
GetPluginVerifier 获取插件的校验值,用于确认各个实例之间的插件版本是否一致
校验是可选的,在氷犬的消息事件系统中实例间的插件是否相同实际上并不影响组网,但是如果插件不同可能会导致一些意想不到的问题
func GetSelfNodeId ¶
func GetSelfNodeId() string
func InitLocalDatabase ¶
func InitLocalDatabase()
func Subscribe ¶
func Subscribe(eventType uint8, summary string, handler EventHandler) string
Subscribe 用于从事件总线订阅事件的快捷方式
func Unsubscribe ¶
Unsubscribe 用于从事件总线取消订阅事件的快捷方式
func UseGlobalPublishMiddleware ¶
func UseGlobalPublishMiddleware(middleware PublishMiddleware)
UseGlobalPublishMiddleware 添加全局发布中间件
func UseSubscribeMiddleware ¶
func UseSubscribeMiddleware(middleware SubscribeMiddleware)
UseSubscribeMiddleware 添加订阅者接收事件中间件
func UseSummaryPublishMiddleware ¶
func UseSummaryPublishMiddleware(summary string, middleware PublishMiddleware)
UseSummaryPublishMiddleware 添加指定摘要发布中间件
func UseTypePublishMiddleware ¶
func UseTypePublishMiddleware(eventType uint8, middleware PublishMiddleware)
UseTypePublishMiddleware 添加指定类型发布中间件
Types ¶
type AdapterConnectEvent ¶
type AdapterConnectEvent struct {
AdapterType string `json:"adapter_type"` // 适配器类型
AdapterModel string `json:"adapter_model"` // 适配器模型
UserId string `json:"user_id"` // 用户ID
UserName string `json:"user_name"` // 用户名称
}
AdapterConnectEvent 8:适配器连接事件结构体
type AdapterDisconnectEvent ¶
type AdapterDisconnectEvent struct {
OK bool `json:"ok"`
}
AdapterDisconnectEvent 9:适配器断开连接事件结构体
type DataCallbackEvent ¶
type DataCallbackEvent struct {
OK bool `json:"ok"` // 回调是否成功
DataType string `json:"data_type"` // 数据类型
Data interface{} `json:"data"` // 回调的数据
RequestSerial int32 `json:"request_serial"` // 请求序列号,用于标识请求防止接受错误
}
DataCallbackEvent 14:数据回调事件,用于节点间的数据传输结构体
type EventBus ¶
type EventBus struct {
// contains filtered or unexported fields
}
EventBus 事件总线结构
var Bus *EventBus
func (*EventBus) GetSubscribers ¶
GetSubscribers 获取订阅者列表,返回订阅 ID 和处理函数
func (*EventBus) Subscribe ¶
func (bus *EventBus) Subscribe(eventType uint8, summary string, handler EventHandler) string
Subscribe 订阅事件,返回订阅 ID
func (*EventBus) Unsubscribe ¶
Unsubscribe 取消订阅,使用订阅 ID
func (*EventBus) UseGlobalPublishMiddleware ¶
func (bus *EventBus) UseGlobalPublishMiddleware(middleware PublishMiddleware)
UseGlobalPublishMiddleware 添加全局发布中间件
func (*EventBus) UseSubscribeMiddleware ¶
func (bus *EventBus) UseSubscribeMiddleware(middleware SubscribeMiddleware)
UseSubscribeMiddleware 添加订阅者接收事件中间件
func (*EventBus) UseSummaryPublishMiddleware ¶
func (bus *EventBus) UseSummaryPublishMiddleware(summary string, middleware PublishMiddleware)
UseSummaryPublishMiddleware 添加指定摘要发布中间件
func (*EventBus) UseTypePublishMiddleware ¶
func (bus *EventBus) UseTypePublishMiddleware(eventType uint8, middleware PublishMiddleware)
UseTypePublishMiddleware 添加指定类型发布中间件
type IceinuEvent ¶
type IceinuEvent struct {
Type uint8 `json:"type"`
From string `json:"from"` // 消息事件来源节点ID
Target string `json:"target"` // 消息事件目标节点ID
Timestamp int64 `json:"timestamp"` // 事件推送的时间戳
Summary string `json:"summary"` // 事件摘要,一般是承载的事件的事件类型,用于在事件总线层快速识别事件类型
Event interface{} `json:"event"` // 事件内容,用于承载不同类型的消息,使用时需要进行断言
}
IceinuEvent Iceinu全局事件结构体
默认的全局事件总线结构体,在直接使用Iceinu框架进行二次开发时使用这个事件结构
引用Iceinu框架作为第三方库时如需自定义自己的事件结构体,需要自行实现事件总线
事件种类: 0:WebSocket心跳事件
1:节点请求建立WebSocket连接事件
2:节点成功连接事件
3:节点断开连接事件
4:节点推送数据事件(主节点到子节点)
5:节点用户推送事件(子节点到主节点)
6:节点请求数据事件(子节点到主节点)
7:节点请求数据事件(主节点到子节点)
8:适配器连接事件
9:适配器断开连接事件
10:消息接收事件
11:消息发送事件
12:节点失活事件(子节点到主节点)
13:节点重新激活事件(子节点到主节点)
14:数据回调事件,用于节点间的数据传输
func MakeAdapterConnectEvent ¶
func MakeAdapterConnectEvent(adapterType string, model string, userId string, userName string) *IceinuEvent
MakeAdapterConnectEvent 创建一个适配器连接事件
func MakeAdapterDisconnectEvent ¶
func MakeAdapterDisconnectEvent() *IceinuEvent
MakeAdapterDisconnectEvent 创建一个适配器断开连接事件
func MakeNodeConnectRequestEvent ¶
func MakeNodeConnectRequestEvent(mode string, adapterModel string, pluginVerifier string) *IceinuEvent
MakeNodeConnectRequestEvent 创建一个节点请求建立WebSocket连接事件
func MakeNodeConnectedEvent ¶
func MakeNodeConnectedEvent() *IceinuEvent
MakeNodeConnectedEvent 创建一个节点成功连接事件
func MakeNodeDeactiveEvent ¶
func MakeNodeDeactiveEvent() *IceinuEvent
MakeNodeDeactiveEvent 创建一个节点失活事件
func MakeNodeDisconnectedEvent ¶
func MakeNodeDisconnectedEvent() *IceinuEvent
MakeNodeDisconnectedEvent 创建一个节点断开连接事件
func MakeNodePushDataEvent ¶
func MakeNodePushDataEvent(data interface{}) *IceinuEvent
MakeNodePushDataEvent 创建一个节点推送数据事件
func MakeNodeReactiveEvent ¶
func MakeNodeReactiveEvent() *IceinuEvent
MakeNodeReactiveEvent 创建一个节点重新激活事件
func MakeNodeRequestDataEvent ¶
func MakeNodeRequestDataEvent(dataType string, key string, query string) *IceinuEvent
MakeNodeRequestDataEvent 创建一个节点请求数据事件
func MakeNodeUserPushEvent ¶
func MakeNodeUserPushEvent(data interface{}) *IceinuEvent
MakeNodeUserPushEvent 创建一个节点用户推送事件
func MakeRequestNodeDataEvent ¶
func MakeRequestNodeDataEvent(dataType string, key string, query string) *IceinuEvent
MakeRequestNodeDataEvent 创建一个请求节点数据事件
func MakeWebsocketHeartbeatEvent ¶
func MakeWebsocketHeartbeatEvent() *IceinuEvent
MakeWebsocketHeartbeatEvent 创建一个WebSocket心跳事件
type IceinuNodeData ¶
type IceinuNodeData struct {
gorm.Model
NodeId string // 节点ID,一般是UUID,每一个节点只会有一个UUID,除非数据被重置
AdapterModel string // 适配器模型
}
IceinuNodeData 氷犬的节点元信息数据表,框架启动时自动初始化
type IceinuPluginList ¶
type IceinuPluginList struct {
PluginId string `gorm:"primaryKey"` // 插件ID,一般是名字
IsEnabled bool // 是否启用
UpdateTime time.Time // 操作时间
IsWhiteList bool // 是否是白名单模式,这个模式会反转禁用逻辑
BanUsers string // 对哪些用户禁用该插件的触发器
BanGroups string // 对哪些群禁用该插件的触发器
BanChannels string // 对哪些频道禁用该插件的触发器
BanNodes string // 对哪些节点禁用该插件
IsDetectUpdate bool // 是否检测更新
}
IceinuPluginList 氷犬的插件信息数据表,用于存储插件的启用状态,并在各个节点之间同步
type NodeConnectRequestEvent ¶
type NodeConnectRequestEvent struct {
Mode string `json:"mode"` // 组网模式
AdapterModel string `json:"adapter_model"` // 适配器模型
PluginVerifier string `json:"plugin_verifier"` // 插件校验值
}
NodeConnectRequestEvent 1:节点请求建立WebSocket连接事件结构体
type NodeConnectedEvent ¶
type NodeConnectedEvent struct {
OK bool `json:"ok"`
}
NodeConnectedEvent 2:节点成功连接事件结构体
type NodeDeactiveEvent ¶
type NodeDeactiveEvent struct {
OK bool `json:"ok"`
}
NodeDeactiveEvent 12:节点失活事件(子节点到主节点)结构体
type NodeDisconnectedEvent ¶
type NodeDisconnectedEvent struct {
OK bool `json:"ok"`
}
NodeDisconnectedEvent 3:节点断开连接事件结构体
type NodePushDataEvent ¶
type NodePushDataEvent struct {
Data interface{} `json:"data"` // 推送的数据
}
NodePushDataEvent 4:节点推送数据事件(主节点到子节点)结构体
type NodeReactiveEvent ¶
type NodeReactiveEvent struct {
OK bool `json:"ok"`
}
NodeReactiveEvent 13:节点重新激活事件(子节点到主节点)结构体
type NodeRequestDataEvent ¶
type NodeRequestDataEvent struct {
RequestSerial int32 `json:"request_serial"` // 请求序列号,用于标识请求防止接受错误
DataType string `json:"data_type"` // 请求的数据类型
Key string `json:"key"` // 请求的数据键
Query string `json:"query"` // 请求的查询内容
}
NodeRequestDataEvent 6:节点请求数据事件(子节点到主节点)结构体
type NodeUserPushEvent ¶
NodeUserPushEvent 5:节点用户推送事件(子节点到主节点)结构体
type PublishMiddleware ¶
type PublishMiddleware func(event *IceinuEvent, next func(event *IceinuEvent))
PublishMiddleware 发布中间件类型
type RequestNodeDataEvent ¶
type RequestNodeDataEvent struct {
RequestSerial int32 `json:"request_serial"` // 请求序列号,用于标识请求防止接受错误
DataType string `json:"data_type"` // 请求的数据类型
Key string `json:"key"` // 请求的数据键
Query string `json:"query"` // 请求的查询内容
}
RequestNodeDataEvent 7:节点请求数据事件(主节点到子节点)结构体
type SubscribeMiddleware ¶
type SubscribeMiddleware func(event *IceinuEvent, next func(event *IceinuEvent))
SubscribeMiddleware 订阅中间件类型
type WebSocketHeartbeatEvent ¶
type WebSocketHeartbeatEvent struct {
OK bool `json:"ok"`
}
WebSocketHeartbeatEvent 0:WebSocket心跳事件结构体