diff --git a/abstract/pre_send_event_handler.go b/abstract/pre_send_event_handler.go index 100494f..9883a4d 100644 --- a/abstract/pre_send_event_handler.go +++ b/abstract/pre_send_event_handler.go @@ -17,13 +17,6 @@ import ( // // Date : 14:06 2023/2/1 type IPreSendHandler interface { - // GetEventID 为每一条事件生成唯一的ID, 此方法若返回空值, 则会自动生成一个随机的md5字符串作为事件ID - // - // Author : go_developer@163.com<白茶清欢> - // - // Date : 14:10 2023/2/1 - GetEventID() string - // GetRequestParam 构造 base info 时, 可能需要从请求参数中提取公共数据 // // Author : go_developer@163.com<白茶清欢> diff --git a/default_pre_send_handler.go b/default_pre_send_handler.go new file mode 100644 index 0000000..11d93b2 --- /dev/null +++ b/default_pre_send_handler.go @@ -0,0 +1,42 @@ +// Package event ... +// +// Description : event ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2023-02-02 16:36 +package event + +import "net/http" + +// DefaultPreSendHandler IPreSendHandler 默认实现 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 16:36 2023/2/2 +type DefaultPreSendHandler struct { +} + +func (d *DefaultPreSendHandler) GetRequestParam() map[string]interface{} { + return map[string]interface{}{} +} + +func (d *DefaultPreSendHandler) GetRequestHeader() http.Header { + return make(map[string][]string, 0) +} + +func (d *DefaultPreSendHandler) GetResponseData() map[string]interface{} { + return map[string]interface{}{} +} + +func (d *DefaultPreSendHandler) GetExtensionData() map[string]interface{} { + return map[string]interface{}{} +} + +func (d *DefaultPreSendHandler) GetEventData() interface{} { + return map[string]interface{}{} +} + +func (d *DefaultPreSendHandler) NeedSend() (map[string]interface{}, bool) { + return map[string]interface{}{}, true +} diff --git a/default_send_event_handler.go b/default_send_event_handler.go new file mode 100644 index 0000000..466644c --- /dev/null +++ b/default_send_event_handler.go @@ -0,0 +1,27 @@ +// Package event ... +// +// Description : event ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2023-02-02 16:39 +package event + +type DefaultSendEventHandler struct { +} + +func (d *DefaultSendEventHandler) Send(data []byte) (map[string]interface{}, error) { + return map[string]interface{}{}, nil +} + +func (d *DefaultSendEventHandler) SuccessCallback(data map[string]interface{}) { + +} + +func (d *DefaultSendEventHandler) FailCallback(data map[string]interface{}, err error) { + +} + +func (d *DefaultSendEventHandler) NoSendCallback(data interface{}, res SendResult) { + +} diff --git a/send.go b/send.go index 70e9e00..73b09c5 100644 --- a/send.go +++ b/send.go @@ -18,6 +18,13 @@ import ( // // Date : 15:16 2023/2/2 func SendEvent(dataFlag string, data interface{}, preSendHandler abstract.IPreSendHandler, sendEventHandler abstract.ISendEventHandler) { + if nil == preSendHandler { + preSendHandler = &DefaultPreSendHandler{} + } + + if nil == sendEventHandler { + sendEventHandler = &DefaultSendEventHandler{} + } // noSendReason, isNeedSend := preSendHandler.NeedSend() _, isNeedSend := preSendHandler.NeedSend() res := SendResult{}