From fb20a61d74c65dec3a4c68640e4a8a4fb80befd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 2 Feb 2023 15:22:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=A5=E5=8F=A3=E5=8F=91?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reflect.go | 4 +++- send.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 send.go 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) + } +}