From 2a67a8b1659a54566509d9ed37c7d01a4a2671d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 1 Feb 2023 14:29:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=84=E7=90=86=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=BA=A6=E6=9D=9F=E4=BB=A5=E5=8F=8A=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E5=80=BC=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 22 +++++++++++ abstract/pre_send_event_handler.go | 62 ++++++++++++++++++++++++++++++ abstract/send_event_handler.go | 38 ++++++++++++++++++ define.go | 42 ++++++++++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 .gitignore create mode 100644 abstract/pre_send_event_handler.go create mode 100644 abstract/send_event_handler.go create mode 100644 define.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..df8e306 --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +# Created by .ignore support plugin (hsz.mobi) +### Go template +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +*.xlsx + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ +.idea +.vscode +mail_test.go + diff --git a/abstract/pre_send_event_handler.go b/abstract/pre_send_event_handler.go new file mode 100644 index 0000000..0393add --- /dev/null +++ b/abstract/pre_send_event_handler.go @@ -0,0 +1,62 @@ +// Package abstract ... +// +// Description : 事件发送前预处理接口约束 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2023-02-01 14:06 +package abstract + +import ( + "net/http" +) + +// IPreSendHandler ... +// +// Author : go_developer@163.com<白茶清欢> +// +// 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<白茶清欢> + // + // Date : 14:13 2023/2/1 + GetRequestParam() map[string]interface{} + + // GetRequestHeader ... + // + // Author : go_developer@163.com<白茶清欢> + // + // Date : 14:14 2023/2/1 + // 构造 base info 时, 可能需要从请求参数中提取公共数据 + GetRequestHeader() http.Header + + // GetResponseData 响应数据 + // + // Author : go_developer@163.com<白茶清欢> + // + // Date : 14:15 2023/2/1 + GetResponseData() map[string]interface{} + + // GetExtensionData 获取扩展数据 + // + // Author : go_developer@163.com<白茶清欢> + // + // Date : 14:19 2023/2/1 + GetExtensionData() map[string]interface{} + + // GetEventData 获取事件数据, 建议返回结构体或者结构体指针, 内部会自动补齐缺失的数据 + // + // Author : go_developer@163.com<白茶清欢> + // + // Date : 14:16 2023/2/1 + GetEventData() interface{} +} diff --git a/abstract/send_event_handler.go b/abstract/send_event_handler.go new file mode 100644 index 0000000..ce3583c --- /dev/null +++ b/abstract/send_event_handler.go @@ -0,0 +1,38 @@ +// Package abstract ... +// +// Description : abstract ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2023-02-01 14:21 +package abstract + +// ISendEventHandler 发送事件处理器 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:21 2023/2/1 +type ISendEventHandler interface { + // Send ... + // + // Author : go_developer@163.com<白茶清欢> + // + // Date : 14:21 2023/2/1 + // 事件发送成功之后, 可以返回一些业务数据, 这些业务数据会回调给SuccessCallback + // 事件发送成功之后, 可以返回一些业务数据 以及 err, 这些业务数据会回调给FailCallback + Send(data []byte) (map[string]interface{}, error) + + // SuccessCallback 事件发送成功的回调 + // + // Author : go_developer@163.com<白茶清欢> + // + // Date : 14:21 2023/2/1 + SuccessCallback(data map[string]interface{}) + + // FailCallback 事件发送失败的回调 + // + // Author : go_developer@163.com<白茶清欢> + // + // Date : 14:22 2023/2/1 + FailCallback(data map[string]interface{}, err error) +} diff --git a/define.go b/define.go new file mode 100644 index 0000000..f3e5667 --- /dev/null +++ b/define.go @@ -0,0 +1,42 @@ +// Package event ... +// +// Description : 各种常量定义 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2023-02-01 14:23 +package event + +const ( + // OutputKeyTag 事件数据输出key的标签 + OutputKeyTag = "event" + // JsonTag json输出的标签 + JsonTag = "json" + // IgnoreTagValue 不做输出的标签值 + IgnoreTagValue = "-" + // MappingTag 参数映射标签 + MappingTag = "mapping" +) + +const ( + // MappingLocationAll 自动探测所有路径 + MappingLocationAll = "all" + // MappingLocationParam 从参数读取 + MappingLocationParam = "param" + // MappingLocationHeader 从请求header读取 + MappingLocationHeader = "header" + // MappingLocationResponse 从响应数据读取 + MappingLocationResponse = "response" + // MappingLocationExtension 从扩展数据读取 + MappingLocationExtension = "extension" +) + +// MappingRule 数据映射规则 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 14:24 2023/2/1 +type MappingRule struct { + Location string `json:"location"` // 数据所在位置, header-请求头 param-参数获取 response-响应数据获取 extension-扩展数据读取 all-自动按照header/param/response/extension的顺序查询 + Field string `json:"field"` // 查询的字段名称 +}