feat(plugins): update gen plugins

This commit is contained in:
bandl 2021-10-19 15:33:03 +08:00
parent 780cf7d276
commit cb1e555986
6 changed files with 35 additions and 69 deletions

View File

@ -6,17 +6,14 @@ package config
import (
"gitee.com/timedb/wheatCache/plugins"
logMiddle "gitee.com/timedb/wheatCache/plugins/log-middle"
mapKey "gitee.com/timedb/wheatCache/plugins/map-key"
mockPlugin "gitee.com/timedb/wheatCache/plugins/mock-plugin"
)
func GetMiddlewareMap() map[string]plugins.MiddleToolsInterface {
func GetMiddlewareMap() map[string]plugins.PluginInterface {
logMiddle := logMiddle.NewMiddleware()
mapKey := mapKey.NewMiddleware()
return map[string]plugins.MiddleToolsInterface{
mockPlugin := mockPlugin.NewPlugin()
return map[string]plugins.PluginInterface{
logMiddle.Name(): logMiddle,
mapKey.Name(): mapKey,
mockPlugin.Name(): mockPlugin,
}
}

View File

@ -11,11 +11,11 @@ import (
)
func GetMiddlewareMap() map[string]plugins.MiddleToolsInterface {
func GetMiddlewareMap() map[string]plugins.PluginInterface {
{%for dir in dirs %}
{{dir[0]}}:={{dir[0]}}.NewMiddleware()
{{dir[0]}}:={{dir[0]}}.NewPlugin()
{%- endfor%}
return map[string]plugins.MiddleToolsInterface{
return map[string]plugins.PluginInterface{
{%for dir in dirs %}
{{dir[0]}}.Name():{{dir[0]}},
{%- endfor%}

View File

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

View File

@ -1,29 +0,0 @@
package logmiddle
import (
"fmt"
"gitee.com/timedb/wheatCache/plugins"
)
type logMiddle struct {
}
func (i *logMiddle) Init() {
}
func (i *logMiddle) Exec(interface{}) (interface{}, error) {
fmt.Println("logMiddle")
return "", nil
}
func (i *logMiddle) Name() string {
return "logMiddle"
}
func (i *logMiddle) Describe() string {
return ""
}
func NewMiddleware() plugins.MiddleToolsInterface {
return &logMiddle{}
}

View File

@ -1,28 +0,0 @@
package logmiddle
import (
"gitee.com/timedb/wheatCache/plugins"
)
type mapKey struct {
}
func (i *mapKey) Init() {
}
func (i *mapKey) Exec(interface{}) (interface{}, error) {
return "", nil
}
func (i *mapKey) Name() string {
return "mapKey"
}
func (i *mapKey) Describe() string {
return ""
}
func NewMiddleware() plugins.MiddleToolsInterface {
return &mapKey{}
}

View File

@ -0,0 +1,26 @@
package mockplugin
import "fmt"
type MockPlugin struct {
}
func (m *MockPlugin) Init() {
}
func (m *MockPlugin) Exec(msg interface{}) (interface{}, error) {
fmt.Println(msg)
return nil, nil
}
func (m *MockPlugin) Name() string {
return "mock-plugins"
}
func (m *MockPlugin) Describe() string {
return "这是一个测试用的插件"
}
func NewPlugin() *MockPlugin {
return &MockPlugin{}
}