fix(middleware): fix plugins Interface

This commit is contained in:
Sodesnei 2021-10-09 18:46:57 +08:00
parent 67747a5b6a
commit 89ee969ef7
3 changed files with 22 additions and 7 deletions

View File

@ -3,7 +3,8 @@ package plugins
import "gitee.com/timedb/wheatCache/pkg/event" import "gitee.com/timedb/wheatCache/pkg/event"
type MiddleToolsInterface interface { type MiddleToolsInterface interface {
Init() // 初始化 Init() // 初始化
Exec(e event.Event) (event.Event, error) // 处理用户发送事件 Exec(e *event.Event) (*event.Event, error) // 处理用户发送事件
Name() string // 获取中间件名称 Name() string // 获取中间件名称
Describe() string // 描述
} }

View File

@ -1,6 +1,8 @@
package log_middle package log_middle
import ( import (
"fmt"
"gitee.com/timedb/wheatCache/pkg/event" "gitee.com/timedb/wheatCache/pkg/event"
"gitee.com/timedb/wheatCache/plugins" "gitee.com/timedb/wheatCache/plugins"
) )
@ -11,7 +13,9 @@ type logMiddle struct {
func (i *logMiddle) Init() { func (i *logMiddle) Init() {
} }
func (i *logMiddle) Exec(e event.Event) (event.Event, error) { func (i *logMiddle) Exec(e *event.Event) (*event.Event, error) {
fmt.Println(e.GetEventName())
return e, nil return e, nil
} }
@ -19,6 +23,9 @@ func (i *logMiddle) Name() string {
return "logMiddle" return "logMiddle"
} }
func (i *logMiddle) Describe() string {
return ""
}
func NewMiddleware() plugins.MiddleToolsInterface { func NewMiddleware() plugins.MiddleToolsInterface {
return &logMiddle{} return &logMiddle{}
} }

View File

@ -1,6 +1,9 @@
package log_middle package log_middle
import ( import (
"fmt"
"gitee.com/timedb/wheatCache/pkg/event"
"gitee.com/timedb/wheatCache/plugins" "gitee.com/timedb/wheatCache/plugins"
) )
@ -10,15 +13,19 @@ type mapKey struct {
func (i *mapKey) Init() { func (i *mapKey) Init() {
} }
func (i *mapKey) Exec(interface{}) (interface{}, error) { func (i *mapKey) Exec(e *event.Event) (*event.Event, error) {
fmt.Println(e.GetEventName())
return nil, nil return e, nil
} }
func (i *mapKey) Name() string { func (i *mapKey) Name() string {
return "mapKey" return "mapKey"
} }
func (i *mapKey) Describe() string {
return ""
}
func NewMiddleware() plugins.MiddleToolsInterface { func NewMiddleware() plugins.MiddleToolsInterface {
return &mapKey{} return &mapKey{}
} }