From 373de8b282ecf7c50e7fbdaa2016571ec9406da7 Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Mon, 4 Oct 2021 19:38:41 +0800 Subject: [PATCH 1/6] fix(middle): rollback --- middleware/config/middle.gen.go | 1 - 1 file changed, 1 deletion(-) diff --git a/middleware/config/middle.gen.go b/middleware/config/middle.gen.go index 6efac1e..10bc962 100644 --- a/middleware/config/middle.gen.go +++ b/middleware/config/middle.gen.go @@ -5,7 +5,6 @@ package config import ( "gitee.com/timedb/wheatCache/middleware" - logMiddle "gitee.com/timedb/wheatCache/middleware/log-middle" mapKey "gitee.com/timedb/wheatCache/middleware/map-key" ) From ea36d370a77aa241eeb87f7fee9c548d731d6645 Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Mon, 4 Oct 2021 20:04:28 +0800 Subject: [PATCH 2/6] fix(middle-driver): update file name --- {middleware => plugins}/config/middle.gen.go | 7 ++++--- {middleware => plugins}/config/middle.template | 4 ++-- {middleware => plugins}/define.go | 0 {middleware => plugins}/log-middle/middleware.go | 0 {middleware => plugins}/map-key/middleware.go | 0 shell/gen_middleware.py | 4 ++-- 6 files changed, 8 insertions(+), 7 deletions(-) rename {middleware => plugins}/config/middle.gen.go (66%) rename {middleware => plugins}/config/middle.template (77%) rename {middleware => plugins}/define.go (100%) rename {middleware => plugins}/log-middle/middleware.go (100%) rename {middleware => plugins}/map-key/middleware.go (100%) diff --git a/middleware/config/middle.gen.go b/plugins/config/middle.gen.go similarity index 66% rename from middleware/config/middle.gen.go rename to plugins/config/middle.gen.go index 10bc962..cb9323d 100644 --- a/middleware/config/middle.gen.go +++ b/plugins/config/middle.gen.go @@ -4,9 +4,10 @@ package config import ( - "gitee.com/timedb/wheatCache/middleware" - logMiddle "gitee.com/timedb/wheatCache/middleware/log-middle" - mapKey "gitee.com/timedb/wheatCache/middleware/map-key" + "gitee.com/timedb/wheatCache/plugins" + + logMiddle "gitee.com/timedb/wheatCache/plugins/log-middle" + mapKey "gitee.com/timedb/wheatCache/plugins/map-key" ) func GetMiddlewareMap() map[string]middleware.MiddleToolsInterface { diff --git a/middleware/config/middle.template b/plugins/config/middle.template similarity index 77% rename from middleware/config/middle.template rename to plugins/config/middle.template index 5bcbc70..1f6d411 100644 --- a/middleware/config/middle.template +++ b/plugins/config/middle.template @@ -4,9 +4,9 @@ package config import ( - "gitee.com/timedb/wheatCache/middleware" + "gitee.com/timedb/wheatCache/plugins" {%for dir in dirs %} - {{dir[0]}} "gitee.com/timedb/wheatCache/middleware/{{dir[1]}}" + {{dir[0]}} "gitee.com/timedb/wheatCache/plugins/{{dir[1]}}" {%- endfor%} ) diff --git a/middleware/define.go b/plugins/define.go similarity index 100% rename from middleware/define.go rename to plugins/define.go diff --git a/middleware/log-middle/middleware.go b/plugins/log-middle/middleware.go similarity index 100% rename from middleware/log-middle/middleware.go rename to plugins/log-middle/middleware.go diff --git a/middleware/map-key/middleware.go b/plugins/map-key/middleware.go similarity index 100% rename from middleware/map-key/middleware.go rename to plugins/map-key/middleware.go diff --git a/shell/gen_middleware.py b/shell/gen_middleware.py index df56692..64ef162 100644 --- a/shell/gen_middleware.py +++ b/shell/gen_middleware.py @@ -3,11 +3,11 @@ from jinja2 import Template sysPath = os.getcwd() -tempPath = f"{sysPath}/middleware/config" +tempPath = f"{sysPath}/plugins/config" structurePath = f"{sysPath}/pkg/structure" protobufPath = f"{sysPath}/protobuf" storagePath = f"{sysPath}/storage" -middlePath = f"{sysPath}/middleware" +middlePath = f"{sysPath}/plugins" def go_fmt(path: str): os.system(f"go fmt {path}") From 0bdbe06376105a6d98039d45a9ab4435d22f9721 Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Mon, 4 Oct 2021 20:54:08 +0800 Subject: [PATCH 3/6] fix(middle): update middleware --- plugins/config/middle.gen.go | 4 ++-- plugins/define.go | 2 +- plugins/log-middle/middleware.go | 4 ++-- plugins/map-key/middleware.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/config/middle.gen.go b/plugins/config/middle.gen.go index cb9323d..addf8c1 100644 --- a/plugins/config/middle.gen.go +++ b/plugins/config/middle.gen.go @@ -10,9 +10,9 @@ import ( mapKey "gitee.com/timedb/wheatCache/plugins/map-key" ) -func GetMiddlewareMap() map[string]middleware.MiddleToolsInterface { +func GetMiddlewareMap() map[string]plugins.MiddleToolsInterface { - return map[string]middleware.MiddleToolsInterface{ + return map[string]plugins.MiddleToolsInterface{ "logMiddle": logMiddle.NewMiddleware(), "mapKey": mapKey.NewMiddleware(), diff --git a/plugins/define.go b/plugins/define.go index 376e5bc..a1befaf 100644 --- a/plugins/define.go +++ b/plugins/define.go @@ -1,4 +1,4 @@ -package middleware +package plugins type MiddleToolsInterface interface { Init() diff --git a/plugins/log-middle/middleware.go b/plugins/log-middle/middleware.go index 386d87f..1bca668 100644 --- a/plugins/log-middle/middleware.go +++ b/plugins/log-middle/middleware.go @@ -3,7 +3,7 @@ package log_middle import ( "fmt" - "gitee.com/timedb/wheatCache/middleware" + "gitee.com/timedb/wheatCache/plugins" ) type A struct { @@ -17,6 +17,6 @@ func (i *A) Exec(interface{}) (interface{}, error) { return nil, nil } -func NewMiddleware() middleware.MiddleToolsInterface { +func NewMiddleware() plugins.MiddleToolsInterface { return &A{} } diff --git a/plugins/map-key/middleware.go b/plugins/map-key/middleware.go index 3f33fba..e188629 100644 --- a/plugins/map-key/middleware.go +++ b/plugins/map-key/middleware.go @@ -3,7 +3,7 @@ package log_middle import ( "fmt" - "gitee.com/timedb/wheatCache/middleware" + "gitee.com/timedb/wheatCache/plugins" ) type ABB struct { @@ -17,6 +17,6 @@ func (i *ABB) Exec(interface{}) (interface{}, error) { return nil, nil } -func NewMiddleware() middleware.MiddleToolsInterface { +func NewMiddleware() plugins.MiddleToolsInterface { return &ABB{} } From 1c9c437a0f45dc31d37f12512f884dbfce74839f Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Mon, 4 Oct 2021 21:10:42 +0800 Subject: [PATCH 4/6] fix(middleware): add middlewareInterface function --- plugins/define.go | 5 +++-- plugins/log-middle/middleware.go | 14 +++++++++----- plugins/map-key/middleware.go | 18 ++++++++++-------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/plugins/define.go b/plugins/define.go index a1befaf..37538c9 100644 --- a/plugins/define.go +++ b/plugins/define.go @@ -1,6 +1,7 @@ package plugins type MiddleToolsInterface interface { - Init() - Exec(interface{}) (interface{}, error) + Init() // 初始化 + Exec(interface{}) (interface{}, error) // 处理用户发送事件 + Name() string // 获取中间件名称 } diff --git a/plugins/log-middle/middleware.go b/plugins/log-middle/middleware.go index 1bca668..c6ff102 100644 --- a/plugins/log-middle/middleware.go +++ b/plugins/log-middle/middleware.go @@ -6,17 +6,21 @@ import ( "gitee.com/timedb/wheatCache/plugins" ) -type A struct { +type logMiddle struct { } -func (i *A) Init() { +func (i *logMiddle) Init() { } -func (i *A) Exec(interface{}) (interface{}, error) { +func (i *logMiddle) Exec(interface{}) (interface{}, error) { fmt.Println(1) return nil, nil } -func NewMiddleware() plugins.MiddleToolsInterface { - return &A{} +func (i *logMiddle) Name() string { + return "logMiddle" +} + +func NewMiddleware() plugins.MiddleToolsInterface { + return &logMiddle{} } diff --git a/plugins/map-key/middleware.go b/plugins/map-key/middleware.go index e188629..31fa509 100644 --- a/plugins/map-key/middleware.go +++ b/plugins/map-key/middleware.go @@ -1,22 +1,24 @@ package log_middle import ( - "fmt" - "gitee.com/timedb/wheatCache/plugins" ) -type ABB struct { +type mapKey struct { } -func (i *ABB) Init() { +func (i *mapKey) Init() { } -func (i *ABB) Exec(interface{}) (interface{}, error) { - fmt.Println(1) +func (i *mapKey) Exec(interface{}) (interface{}, error) { + return nil, nil } -func NewMiddleware() plugins.MiddleToolsInterface { - return &ABB{} +func (i *mapKey) Name() string { + return "mapKey" +} + +func NewMiddleware() plugins.MiddleToolsInterface { + return &mapKey{} } From bd804e71059b7fd2afdd382c9a3b38da84a89daf Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Mon, 4 Oct 2021 21:12:14 +0800 Subject: [PATCH 5/6] fix(middle): update define --- pkg/middle/define.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/middle/define.go b/pkg/middle/define.go index a74bd76..678c75b 100644 --- a/pkg/middle/define.go +++ b/pkg/middle/define.go @@ -1,6 +1,6 @@ package middle -import getMiddlewareMap "gitee.com/timedb/wheatCache/middleware/config" +import getMiddlewareMap "gitee.com/timedb/wheatCache/plugins/config" func Init() { getMiddlewareMap.GetMiddlewareMap() From 49496cf63c67b9667d4d1f8b630d1fbdc8a6d123 Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Mon, 4 Oct 2021 21:15:23 +0800 Subject: [PATCH 6/6] fix(middle): fix middle.template --- plugins/config/middle.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/config/middle.template b/plugins/config/middle.template index 1f6d411..10b56e8 100644 --- a/plugins/config/middle.template +++ b/plugins/config/middle.template @@ -11,9 +11,9 @@ import ( ) -func GetMiddlewareMap() map[string]middleware.MiddleToolsInterface { +func GetMiddlewareMap() map[string]plugins.MiddleToolsInterface { - return map[string]middleware.MiddleToolsInterface{ + return map[string]plugins.MiddleToolsInterface{ {%for dir in dirs %} "{{dir[0]}}":{{dir[0]}}.NewMiddleware(), {%- endfor%}