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
type MiddleToolsInterface interface {
Init()
Exec(interface{}) (interface{}, error)
Init() // 初始化
Exec(interface{}) (interface{}, error) // 处理用户发送事件
Name() string // 获取中间件名称
}

View File

@ -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{}
}

View File

@ -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{}
}