fix(middleware): add middlewareInterface function

This commit is contained in:
Sodesnei 2021-10-04 21:10:42 +08:00
parent 0bdbe06376
commit 1c9c437a0f
3 changed files with 22 additions and 15 deletions

View File

@ -1,6 +1,7 @@
package plugins package plugins
type MiddleToolsInterface interface { type MiddleToolsInterface interface {
Init() Init() // 初始化
Exec(interface{}) (interface{}, error) Exec(interface{}) (interface{}, error) // 处理用户发送事件
Name() string // 获取中间件名称
} }

View File

@ -6,17 +6,21 @@ import (
"gitee.com/timedb/wheatCache/plugins" "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) fmt.Println(1)
return nil, nil return nil, nil
} }
func NewMiddleware() plugins.MiddleToolsInterface { func (i *logMiddle) Name() string {
return &A{} return "logMiddle"
}
func NewMiddleware() plugins.MiddleToolsInterface {
return &logMiddle{}
} }

View File

@ -1,22 +1,24 @@
package log_middle package log_middle
import ( import (
"fmt"
"gitee.com/timedb/wheatCache/plugins" "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) { func (i *mapKey) Exec(interface{}) (interface{}, error) {
fmt.Println(1)
return nil, nil return nil, nil
} }
func NewMiddleware() plugins.MiddleToolsInterface { func (i *mapKey) Name() string {
return &ABB{} return "mapKey"
}
func NewMiddleware() plugins.MiddleToolsInterface {
return &mapKey{}
} }