feat(plugins): update gen plugins
This commit is contained in:
parent
780cf7d276
commit
cb1e555986
|
@ -6,17 +6,14 @@ package config
|
||||||
import (
|
import (
|
||||||
"gitee.com/timedb/wheatCache/plugins"
|
"gitee.com/timedb/wheatCache/plugins"
|
||||||
|
|
||||||
logMiddle "gitee.com/timedb/wheatCache/plugins/log-middle"
|
mockPlugin "gitee.com/timedb/wheatCache/plugins/mock-plugin"
|
||||||
mapKey "gitee.com/timedb/wheatCache/plugins/map-key"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetMiddlewareMap() map[string]plugins.MiddleToolsInterface {
|
func GetMiddlewareMap() map[string]plugins.PluginInterface {
|
||||||
|
|
||||||
logMiddle := logMiddle.NewMiddleware()
|
mockPlugin := mockPlugin.NewPlugin()
|
||||||
mapKey := mapKey.NewMiddleware()
|
return map[string]plugins.PluginInterface{
|
||||||
return map[string]plugins.MiddleToolsInterface{
|
|
||||||
|
|
||||||
logMiddle.Name(): logMiddle,
|
mockPlugin.Name(): mockPlugin,
|
||||||
mapKey.Name(): mapKey,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func GetMiddlewareMap() map[string]plugins.MiddleToolsInterface {
|
func GetMiddlewareMap() map[string]plugins.PluginInterface {
|
||||||
{%for dir in dirs %}
|
{%for dir in dirs %}
|
||||||
{{dir[0]}}:={{dir[0]}}.NewMiddleware()
|
{{dir[0]}}:={{dir[0]}}.NewPlugin()
|
||||||
{%- endfor%}
|
{%- endfor%}
|
||||||
return map[string]plugins.MiddleToolsInterface{
|
return map[string]plugins.PluginInterface{
|
||||||
{%for dir in dirs %}
|
{%for dir in dirs %}
|
||||||
{{dir[0]}}.Name():{{dir[0]}},
|
{{dir[0]}}.Name():{{dir[0]}},
|
||||||
{%- endfor%}
|
{%- endfor%}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package plugins
|
package plugins
|
||||||
|
|
||||||
type MiddleToolsInterface interface {
|
type PluginInterface interface {
|
||||||
Init() // 初始化
|
Init() // 初始化
|
||||||
Exec(interface{}) (interface{}, error) // 处理用户发送事件
|
Exec(interface{}) (interface{}, error) // 处理用户发送事件
|
||||||
Name() string // 获取中间件名称
|
Name() string // 获取中间件名称
|
||||||
|
|
|
@ -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{}
|
|
||||||
}
|
|
|
@ -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{}
|
|
||||||
}
|
|
|
@ -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{}
|
||||||
|
}
|
Loading…
Reference in New Issue