2 Star 1 Fork 2

go-mao/mao

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
hook_domain.go 819 Bytes
一键复制 编辑 原始数据 按行查看 历史
haitgo 提交于 2023-03-08 11:04 +08:00 . 增加模块限制功能
package frame
import (
"sync"
)
type hookDomain struct {
sync.Mutex
server *Server
eventsMap map[string][]EventInterface
}
// 初始化事件驾照
func (this *hookDomain) init(module ModuleInterface) {
if this.eventsMap == nil {
this.eventsMap = make(map[string][]EventInterface)
}
events := module.Events()
for _, event := range events {
key := event.HookCode()
m, ok := this.eventsMap[key]
if !ok {
this.eventsMap[key] = make([]EventInterface, 0)
m = make([]EventInterface, 0)
}
this.eventsMap[key] = append(m, event)
}
}
// 触发钩子
func (this *hookDomain) trigger(tl *Taskline, h HookInterface, args ...any) {
this.Lock()
defer this.Unlock()
events, ok := this.eventsMap[h.HookCode()]
if !ok {
return
}
for _, event := range events {
event.Handler(tl, args...)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/go-mao/mao.git
git@gitee.com:go-mao/mao.git
go-mao
mao
mao
v1.0.9

搜索帮助