From b6c460186026c08d3313f9779ddd78a16c7f9c28 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:30:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=84=E7=90=86=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=AE=9A=E4=B9=89=20+=20=E5=A2=9E=E5=8A=A0=E6=97=A0?= =?UTF-8?q?=E9=9C=80=E5=8F=91=E9=80=81=E4=BA=8B=E4=BB=B6=E7=9A=84=E5=9B=9E?= =?UTF-8?q?=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abstract/pre_send_event_handler.go | 4 ++-- abstract/send_event_handler.go | 9 +++++++++ define.go | 8 ++++++++ send.go | 6 +++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/abstract/pre_send_event_handler.go b/abstract/pre_send_event_handler.go index cd7784f..100494f 100644 --- a/abstract/pre_send_event_handler.go +++ b/abstract/pre_send_event_handler.go @@ -60,10 +60,10 @@ type IPreSendHandler interface { // Date : 14:16 2023/2/1 GetEventData() interface{} - // NeedSend 判断是否需要发送事件 + // NeedSend 判断是否需要发送事件, 若不需要发送, 可在第一个返回值中记录不需要发送的原因 // // Author : go_developer@163.com<白茶清欢> // // Date : 15:24 2023/2/2 - NeedSend() bool + NeedSend() (map[string]interface{}, bool) } diff --git a/abstract/send_event_handler.go b/abstract/send_event_handler.go index ce3583c..5b9de5b 100644 --- a/abstract/send_event_handler.go +++ b/abstract/send_event_handler.go @@ -7,6 +7,8 @@ // Date : 2023-02-01 14:21 package abstract +import "git.zhangdeman.cn/zhangdeman/event" + // ISendEventHandler 发送事件处理器 // // Author : go_developer@163.com<白茶清欢> @@ -35,4 +37,11 @@ type ISendEventHandler interface { // // Date : 14:22 2023/2/1 FailCallback(data map[string]interface{}, err error) + + // NoSendCallback 不需要发送事件的回调 + // + // Author : go_developer@163.com<白茶清欢> + // + // Date : 15:26 2023/2/2 + NoSendCallback(data interface{}, res event.SendResult) } diff --git a/define.go b/define.go index 47d4216..6e5bb67 100644 --- a/define.go +++ b/define.go @@ -93,3 +93,11 @@ type StructInfo struct { IsStructPtr bool // 是否为结构体指针 StructFieldList []*StructField // 结构体字段列表 } + +// SendResult ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 15:27 2023/2/2 +type SendResult struct { +} diff --git a/send.go b/send.go index 573d227..70e9e00 100644 --- a/send.go +++ b/send.go @@ -18,7 +18,11 @@ import ( // // Date : 15:16 2023/2/2 func SendEvent(dataFlag string, data interface{}, preSendHandler abstract.IPreSendHandler, sendEventHandler abstract.ISendEventHandler) { - if !preSendHandler.NeedSend() { + // noSendReason, isNeedSend := preSendHandler.NeedSend() + _, isNeedSend := preSendHandler.NeedSend() + res := SendResult{} + if !isNeedSend { + sendEventHandler.NoSendCallback(data, res) return } // 通过反射填充数据