From ec8cea59a4960771b4031a7952198b33ab1455aa Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Sun, 10 Oct 2021 22:26:03 +0800 Subject: [PATCH 1/3] feat(doc): middleware doc --- doc/pkg/middle/middle.md | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 doc/pkg/middle/middle.md diff --git a/doc/pkg/middle/middle.md b/doc/pkg/middle/middle.md new file mode 100644 index 0000000..51eec50 --- /dev/null +++ b/doc/pkg/middle/middle.md @@ -0,0 +1,47 @@ +### 中间件调用 + + +### 创建事件 + +event := event.NewEvent("logcontext") + + +### 创建驱动 + +middleware := NewMiddleWare() + +### 将事件推入驱动 + +middleware.eventProduce.Call(ctx, event) + + +### 获取驱动的事件 +middleware.eventConsumer.Reciver(ctx) + + + +### 插件接口 +type MiddleToolsInterface interface { + Init() // 初始化 + Exec(interface{}) (interface{}, error) // 处理用户发送事件 + Name() string // 获取中间件名称 + Describe() string // 描述 +} + +### 插件的New方法规定为 NewMiddleWare() + 每个插件都要定义NewMiddleWare() + + + +### 将插件名 “logMiddle” 注册到配置文件wheat-cache.yaml,其他插件注册 +plugins-control: + logcontext: ["logMiddle"] + + + + + + + + + From e2f00fa2aeac69c0b0843261f43dacfb5cfa2cfb Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Sun, 10 Oct 2021 22:26:54 +0800 Subject: [PATCH 2/3] feat(middle-msg): add SendMiddleMsg function --- pkg/middle-msg/define.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pkg/middle-msg/define.go b/pkg/middle-msg/define.go index f7621e9..a275e6c 100644 --- a/pkg/middle-msg/define.go +++ b/pkg/middle-msg/define.go @@ -1,5 +1,34 @@ package middle_msg +import ( + "context" + + "gitee.com/timedb/wheatCache/pkg/errorx" + "gitee.com/timedb/wheatCache/pkg/event" +) + const ( MiddleMsgKey = "middleMsgKey" ) + +func SendMiddleMsg( + ctx context.Context, + middleProduce event.ProduceInterface, + val interface{}, +) error { + if middleProduce == nil { + return errorx.New("middleProduce not is nil") + } + + var eventName string + + switch val.(type) { + case LogContext: + eventName = EventNameLog + } + + msgEvent := event.NewEvent(eventName) + msgEvent.SetValue(MiddleMsgKey, val) + middleProduce.Call(ctx, msgEvent) + return nil +} From 44dbb04f0b1928d6d190f3478549f08d3ff604e9 Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Sun, 10 Oct 2021 22:27:37 +0800 Subject: [PATCH 3/3] feat(middle-msg): add PluginsInfo msg --- pkg/middle-msg/plugins.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/middle-msg/plugins.go b/pkg/middle-msg/plugins.go index 5a80ec8..366f6a5 100644 --- a/pkg/middle-msg/plugins.go +++ b/pkg/middle-msg/plugins.go @@ -1,8 +1,23 @@ package middle_msg +import ( + "time" +) + // []pulginsINfo // 1. Version // 2. desc // 3. Name // 4. 运行状态 -// 5. 运行时间 + +const ( + EventNamePlug = "plugins-info" +) + +type PulginsInfo struct { + Version string + Desc string + Name string + Statux string + Time time.Duration +}