You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.6 KiB
Go
81 lines
1.6 KiB
Go
package plugin
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/noahlann/nnet/pkg/config"
|
|
)
|
|
|
|
// Plugin 插件接口
|
|
type Plugin interface {
|
|
// Name 获取插件名称
|
|
Name() string
|
|
|
|
// Version 获取插件版本
|
|
Version() string
|
|
|
|
// Init 初始化插件
|
|
Init(config *config.Config) error
|
|
|
|
// Start 启动插件
|
|
Start(ctx context.Context) error
|
|
|
|
// Stop 停止插件
|
|
Stop(ctx context.Context) error
|
|
}
|
|
|
|
// ServerPlugin 服务器插件接口
|
|
type ServerPlugin interface {
|
|
Plugin
|
|
|
|
// OnServerStart 服务器启动时调用
|
|
OnServerStart(ctx context.Context) error
|
|
|
|
// OnServerStop 服务器停止时调用
|
|
OnServerStop(ctx context.Context) error
|
|
}
|
|
|
|
// ConnectionPlugin 连接插件接口
|
|
type ConnectionPlugin interface {
|
|
Plugin
|
|
|
|
// OnConnectionOpen 连接打开时调用
|
|
OnConnectionOpen(ctx context.Context, connID string) error
|
|
|
|
// OnConnectionClose 连接关闭时调用
|
|
OnConnectionClose(ctx context.Context, connID string) error
|
|
}
|
|
|
|
// MessagePlugin 消息插件接口
|
|
type MessagePlugin interface {
|
|
Plugin
|
|
|
|
// OnMessage 消息到达时调用
|
|
OnMessage(ctx context.Context, data []byte) ([]byte, error)
|
|
}
|
|
|
|
// Manager 插件管理器接口
|
|
type Manager interface {
|
|
// Register 注册插件
|
|
Register(plugin Plugin) error
|
|
|
|
// Unregister 取消注册插件
|
|
Unregister(name string) error
|
|
|
|
// Get 获取插件
|
|
Get(name string) (Plugin, error)
|
|
|
|
// List 列出所有插件
|
|
List() []Plugin
|
|
|
|
// InitAll 初始化所有插件
|
|
InitAll(config *config.Config) error
|
|
|
|
// StartAll 启动所有插件
|
|
StartAll(ctx context.Context) error
|
|
|
|
// StopAll 停止所有插件
|
|
StopAll(ctx context.Context) error
|
|
}
|
|
|