diff --git a/define.go b/define.go index 6e5bb67..0c083a8 100644 --- a/define.go +++ b/define.go @@ -100,4 +100,10 @@ type StructInfo struct { // // Date : 15:27 2023/2/2 type SendResult struct { + IsNeedSend bool `json:"is_need_send"` // 是否需要发送 + NoSendDetail map[string]interface{} `json:"no_send_detail"` // 未发送详细原因 + Data interface{} `json:"data"` // 发送的数据 + IsSuccess bool `json:"is_success"` // 是否处理成功 + FailReason string `json:"fail_reason"` // 失败原因 + SendResult map[string]interface{} `json:"send_result"` // 发送结果 } diff --git a/send.go b/send.go index 73b09c5..ef717c0 100644 --- a/send.go +++ b/send.go @@ -17,7 +17,7 @@ import ( // Author : go_developer@163.com<白茶清欢> // // Date : 15:16 2023/2/2 -func SendEvent(dataFlag string, data interface{}, preSendHandler abstract.IPreSendHandler, sendEventHandler abstract.ISendEventHandler) { +func SendEvent(dataFlag string, data interface{}, preSendHandler abstract.IPreSendHandler, sendEventHandler abstract.ISendEventHandler) SendResult { if nil == preSendHandler { preSendHandler = &DefaultPreSendHandler{} } @@ -25,26 +25,33 @@ func SendEvent(dataFlag string, data interface{}, preSendHandler abstract.IPreSe if nil == sendEventHandler { sendEventHandler = &DefaultSendEventHandler{} } - // noSendReason, isNeedSend := preSendHandler.NeedSend() - _, isNeedSend := preSendHandler.NeedSend() res := SendResult{} - if !isNeedSend { + + if res.NoSendDetail, res.IsNeedSend = preSendHandler.NeedSend(); !res.IsNeedSend { sendEventHandler.NoSendCallback(data, res) - return + return res } // 通过反射填充数据 ReflectValueInstance.Do(dataFlag, data, preSendHandler) - if byteData, err := json.Marshal(data); nil != err { + res.Data = data + var ( + byteData []byte + err error + ) + + if byteData, err = json.Marshal(data); nil != err { + res.IsSuccess = false + res.FailReason = err.Error() 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) + return res } + if res.SendResult, err = sendEventHandler.Send(byteData); nil != err { + sendEventHandler.FailCallback(res.SendResult, err) + return res + } + sendEventHandler.SuccessCallback(res.SendResult) + return res }