From 02b048a24f0ac65907ba3f48ca7177e6903ba8ea Mon Sep 17 00:00:00 2001 From: Sodesnei <1452401269@qq.com> Date: Tue, 5 Oct 2021 10:39:53 +0800 Subject: [PATCH] fix(middle-driver):updata middledriver Init() func --- pkg/middle/define.go | 16 +++++++++++++--- pkg/middle/middleware_driver.go | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 pkg/middle/middleware_driver.go diff --git a/pkg/middle/define.go b/pkg/middle/define.go index 678c75b..fcc5f63 100644 --- a/pkg/middle/define.go +++ b/pkg/middle/define.go @@ -1,7 +1,17 @@ package middle -import getMiddlewareMap "gitee.com/timedb/wheatCache/plugins/config" +import ( + "sync" -func Init() { - getMiddlewareMap.GetMiddlewareMap() + "gitee.com/timedb/wheatCache/plugins" + getMiddlewareMap "gitee.com/timedb/wheatCache/plugins/config" +) + +func Init() map[string]plugins.MiddleToolsInterface { + return getMiddlewareMap.GetMiddlewareMap() } + +var ( + oneMiddle sync.Once + MiddleWareDriver *MiddleWare +) diff --git a/pkg/middle/middleware_driver.go b/pkg/middle/middleware_driver.go new file mode 100644 index 0000000..5c58e03 --- /dev/null +++ b/pkg/middle/middleware_driver.go @@ -0,0 +1,34 @@ +package middle + +import ( + "context" + "fmt" + + "gitee.com/timedb/wheatCache/pkg/event" +) + +type MiddleWare struct { + eventDriver event.DriverInterface + eventConsumer event.ConsumerInterface +} + +func NewMiddleWare() *MiddleWare { + oneMiddle.Do(func() { + driver := event.NewDriver(1000) + MiddleWareDriver = &MiddleWare{ + eventDriver: driver, + eventConsumer: event.NewConsumer(driver), + } + }) + return MiddleWareDriver +} + +func (m *MiddleWare) GetEventDriver() event.DriverInterface { + return m.eventDriver +} + +func (m *MiddleWare) work(ctx context.Context) { + getMiddlewareMap := Init() + fmt.Println(getMiddlewareMap) + +}