增加接口的默认实现
This commit is contained in:
parent
b6c4601860
commit
04fed6ffbd
@ -17,13 +17,6 @@ import (
|
|||||||
//
|
//
|
||||||
// Date : 14:06 2023/2/1
|
// Date : 14:06 2023/2/1
|
||||||
type IPreSendHandler interface {
|
type IPreSendHandler interface {
|
||||||
// GetEventID 为每一条事件生成唯一的ID, 此方法若返回空值, 则会自动生成一个随机的md5字符串作为事件ID
|
|
||||||
//
|
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
|
||||||
//
|
|
||||||
// Date : 14:10 2023/2/1
|
|
||||||
GetEventID() string
|
|
||||||
|
|
||||||
// GetRequestParam 构造 base info 时, 可能需要从请求参数中提取公共数据
|
// GetRequestParam 构造 base info 时, 可能需要从请求参数中提取公共数据
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
42
default_pre_send_handler.go
Normal file
42
default_pre_send_handler.go
Normal file
@ -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
|
||||||
|
}
|
27
default_send_event_handler.go
Normal file
27
default_send_event_handler.go
Normal file
@ -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) {
|
||||||
|
|
||||||
|
}
|
7
send.go
7
send.go
@ -18,6 +18,13 @@ import (
|
|||||||
//
|
//
|
||||||
// Date : 15:16 2023/2/2
|
// 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) {
|
||||||
|
if nil == preSendHandler {
|
||||||
|
preSendHandler = &DefaultPreSendHandler{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if nil == sendEventHandler {
|
||||||
|
sendEventHandler = &DefaultSendEventHandler{}
|
||||||
|
}
|
||||||
// noSendReason, isNeedSend := preSendHandler.NeedSend()
|
// noSendReason, isNeedSend := preSendHandler.NeedSend()
|
||||||
_, isNeedSend := preSendHandler.NeedSend()
|
_, isNeedSend := preSendHandler.NeedSend()
|
||||||
res := SendResult{}
|
res := SendResult{}
|
||||||
|
Loading…
Reference in New Issue
Block a user