diff --git a/reflect.go b/reflect.go index 7efd2ef..b1abfdc 100644 --- a/reflect.go +++ b/reflect.go @@ -20,7 +20,8 @@ import ( var ( // ReflectTypeInstance 反射实例 - ReflectTypeInstance *ReflectType + ReflectTypeInstance *ReflectType + ReflectValueInstance *ReflectValue ) func init() { @@ -28,6 +29,7 @@ func init() { lock: &sync.RWMutex{}, cacheTable: make(map[string]*StructInfo), } + ReflectValueInstance = &ReflectValue{} } // ReflectType 反射数据类型 diff --git a/send.go b/send.go new file mode 100644 index 0000000..75788c4 --- /dev/null +++ b/send.go @@ -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) + } +}