增加SendResult
This commit is contained in:
parent
04fed6ffbd
commit
8b73672fa9
@ -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"` // 发送结果
|
||||
}
|
||||
|
31
send.go
31
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
|
||||
return res
|
||||
}
|
||||
sendEventHandler.SuccessCallback(sendResult)
|
||||
if res.SendResult, err = sendEventHandler.Send(byteData); nil != err {
|
||||
sendEventHandler.FailCallback(res.SendResult, err)
|
||||
return res
|
||||
}
|
||||
sendEventHandler.SuccessCallback(res.SendResult)
|
||||
return res
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user