增加入口发时间方法

This commit is contained in:
白茶清欢 2023-02-02 15:22:26 +08:00
parent ea3f8df7d1
commit fb20a61d74
2 changed files with 39 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import (
var ( var (
// ReflectTypeInstance 反射实例 // ReflectTypeInstance 反射实例
ReflectTypeInstance *ReflectType ReflectTypeInstance *ReflectType
ReflectValueInstance *ReflectValue
) )
func init() { func init() {
@ -28,6 +29,7 @@ func init() {
lock: &sync.RWMutex{}, lock: &sync.RWMutex{},
cacheTable: make(map[string]*StructInfo), cacheTable: make(map[string]*StructInfo),
} }
ReflectValueInstance = &ReflectValue{}
} }
// ReflectType 反射数据类型 // ReflectType 反射数据类型

36
send.go Normal file
View File

@ -0,0 +1,36 @@
// Package event ...
//
// Description : event ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2023-02-02 15:15
package event
import (
"encoding/json"
"git.zhangdeman.cn/zhangdeman/event/abstract"
)
// SendEvent 发送事件
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 15:16 2023/2/2
func SendEvent(dataFlag string, data interface{}, preSendHandler abstract.IPreSendHandler, sendEventHandler abstract.ISendEventHandler) {
// 通过反射填充数据
ReflectValueInstance.Do(dataFlag, data, preSendHandler)
if byteData, err := json.Marshal(data); nil != err {
sendEventHandler.FailCallback(map[string]interface{}{
"err": err.Error(),
"reason": "data marshal fail",
}, err)
} else {
sendResult, sendErr := sendEventHandler.Send(byteData)
if nil != sendErr {
sendEventHandler.FailCallback(sendResult, sendErr)
return
}
sendEventHandler.SuccessCallback(sendResult)
}
}