Documentation
¶
Index ¶
- type APIImplementation
- func (api *APIImplementation) GetConfig() types.Config
- func (api *APIImplementation) GetData(key string) (interface{}, error)
- func (api *APIImplementation) GetLogger(pluginName string) Logger
- func (api *APIImplementation) GetMetrics() map[string]interface{}
- func (api *APIImplementation) SendNotification(title, message string) error
- func (api *APIImplementation) StoreData(key string, value interface{}) error
- type ConfigManager
- func (cm *ConfigManager) CreatePluginConfigTemplate(pluginName string, info PluginInfo) error
- func (cm *ConfigManager) DeletePluginConfig(pluginName string) error
- func (cm *ConfigManager) ExportConfigs(exportDir string) error
- func (cm *ConfigManager) ListPluginConfigs() ([]string, error)
- func (cm *ConfigManager) LoadGlobalConfig() (GlobalConfig, error)
- func (cm *ConfigManager) LoadPluginConfig(pluginName string) (PluginConfig, error)
- func (cm *ConfigManager) SaveGlobalConfig(config GlobalConfig) error
- func (cm *ConfigManager) SavePluginConfig(pluginName string, config PluginConfig) error
- func (cm *ConfigManager) ValidateConfigFiles() error
- type ConnectionInterceptor
- type DataProcessor
- type DataStorage
- type GlobalConfig
- type HookExecutor
- func (he *HookExecutor) ExecuteConnectionEndHooks(ctx context.Context, conn types.Connection, duration time.Duration) error
- func (he *HookExecutor) ExecuteConnectionStartHooks(ctx context.Context, conn types.Connection) error
- func (he *HookExecutor) ExecuteDataProcessHooks(ctx context.Context, data []byte, direction types.PacketDirection) ([]byte, error)
- func (he *HookExecutor) ExecuteRequestHooks(ctx context.Context, interceptCtx *InterceptContext) (*InterceptResult, error)
- func (he *HookExecutor) ExecuteResponseHooks(ctx context.Context, interceptCtx *InterceptContext) (*InterceptResult, error)
- func (he *HookExecutor) ExecuteWebSocketMessageHooks(ctx context.Context, wsCtx *WebSocketContext) (*InterceptResult, error)
- func (he *HookExecutor) GetHookStats() map[string]interface{}
- type InterceptContext
- type InterceptResult
- type InterceptorType
- type Logger
- type ManagerConfig
- type MetricsCollector
- type Plugin
- type PluginAPI
- type PluginConfig
- type PluginFactory
- type PluginInfo
- type PluginLogger
- type PluginManager
- func (pm *PluginManager) GetConnectionInterceptors() []ConnectionInterceptor
- func (pm *PluginManager) GetDataProcessors() []DataProcessor
- func (pm *PluginManager) GetPluginList() map[string]*PluginMetadata
- func (pm *PluginManager) GetRequestInterceptors() []RequestInterceptor
- func (pm *PluginManager) GetResponseInterceptors() []ResponseInterceptor
- func (pm *PluginManager) GetWebSocketInterceptors() []WebSocketInterceptor
- func (pm *PluginManager) LoadPlugins() error
- func (pm *PluginManager) RegisterFactory(name string, factory PluginFactory)
- func (pm *PluginManager) Shutdown() error
- func (pm *PluginManager) StartPlugins() error
- func (pm *PluginManager) StopPlugins() error
- type PluginMetadata
- type RequestInterceptor
- type ResponseInterceptor
- type SecurityConfig
- type WebSocketContext
- type WebSocketDirection
- type WebSocketInterceptor
- type WebSocketMessageType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIImplementation ¶
type APIImplementation struct {
// contains filtered or unexported fields
}
APIImplementation 插件API实现
func NewAPIImplementation ¶
func NewAPIImplementation(config types.Config, logger types.Logger) *APIImplementation
NewAPIImplementation 创建API实现
func (*APIImplementation) GetConfig ¶
func (api *APIImplementation) GetConfig() types.Config
GetConfig 获取应用配置
func (*APIImplementation) GetData ¶
func (api *APIImplementation) GetData(key string) (interface{}, error)
GetData 获取数据
func (*APIImplementation) GetLogger ¶
func (api *APIImplementation) GetLogger(pluginName string) Logger
GetLogger 获取日志器
func (*APIImplementation) GetMetrics ¶
func (api *APIImplementation) GetMetrics() map[string]interface{}
GetMetrics 获取指标
func (*APIImplementation) SendNotification ¶
func (api *APIImplementation) SendNotification(title, message string) error
SendNotification 发送通知
func (*APIImplementation) StoreData ¶
func (api *APIImplementation) StoreData(key string, value interface{}) error
StoreData 存储数据
type ConfigManager ¶
type ConfigManager struct {
// contains filtered or unexported fields
}
ConfigManager 配置管理器
func NewConfigManager ¶
func NewConfigManager(configDir string, logger Logger) *ConfigManager
NewConfigManager 创建配置管理器
func (*ConfigManager) CreatePluginConfigTemplate ¶
func (cm *ConfigManager) CreatePluginConfigTemplate(pluginName string, info PluginInfo) error
CreatePluginConfigTemplate 创建插件配置模板
func (*ConfigManager) DeletePluginConfig ¶
func (cm *ConfigManager) DeletePluginConfig(pluginName string) error
DeletePluginConfig 删除插件配置
func (*ConfigManager) ExportConfigs ¶
func (cm *ConfigManager) ExportConfigs(exportDir string) error
ExportConfigs 导出所有配置
func (*ConfigManager) ListPluginConfigs ¶
func (cm *ConfigManager) ListPluginConfigs() ([]string, error)
ListPluginConfigs 列出所有插件配置
func (*ConfigManager) LoadGlobalConfig ¶
func (cm *ConfigManager) LoadGlobalConfig() (GlobalConfig, error)
LoadGlobalConfig 加载全局配置
func (*ConfigManager) LoadPluginConfig ¶
func (cm *ConfigManager) LoadPluginConfig(pluginName string) (PluginConfig, error)
LoadPluginConfig 加载插件配置
func (*ConfigManager) SaveGlobalConfig ¶
func (cm *ConfigManager) SaveGlobalConfig(config GlobalConfig) error
SaveGlobalConfig 保存全局配置
func (*ConfigManager) SavePluginConfig ¶
func (cm *ConfigManager) SavePluginConfig(pluginName string, config PluginConfig) error
SavePluginConfig 保存插件配置
func (*ConfigManager) ValidateConfigFiles ¶
func (cm *ConfigManager) ValidateConfigFiles() error
ValidateConfigFiles 验证所有配置文件
type ConnectionInterceptor ¶
type ConnectionInterceptor interface {
Plugin
// OnConnectionStart 连接开始时调用
OnConnectionStart(ctx context.Context, conn types.Connection) error
// OnConnectionEnd 连接结束时调用
OnConnectionEnd(ctx context.Context, conn types.Connection, duration time.Duration) error
}
ConnectionInterceptor 连接拦截器接口
type DataProcessor ¶
type DataProcessor interface {
Plugin
// ProcessData 处理数据
ProcessData(ctx context.Context, data []byte, direction types.PacketDirection) ([]byte, error)
}
DataProcessor 数据处理器接口
type DataStorage ¶
type DataStorage struct {
// contains filtered or unexported fields
}
DataStorage 数据存储
type GlobalConfig ¶
type GlobalConfig struct {
// 插件系统启用状态
Enabled bool `json:"enabled"`
// 插件目录
PluginsDir string `json:"plugins_dir"`
// 配置目录
ConfigDir string `json:"config_dir"`
// 自动加载插件
AutoLoad bool `json:"auto_load"`
// 热重载
EnableHotReload bool `json:"enable_hot_reload"`
// 默认插件优先级
DefaultPriority int `json:"default_priority"`
// 全局白名单
GlobalWhitelist []string `json:"global_whitelist"`
// 全局黑名单
GlobalBlacklist []string `json:"global_blacklist"`
// 插件超时设置
LoadTimeout int `json:"load_timeout_seconds"`
ExecuteTimeout int `json:"execute_timeout_seconds"`
// 安全设置
Security SecurityConfig `json:"security"`
}
GlobalConfig 全局插件配置
type HookExecutor ¶
type HookExecutor struct {
// contains filtered or unexported fields
}
HookExecutor 钩子执行器
func NewHookExecutor ¶
func NewHookExecutor(manager *PluginManager, logger types.Logger) *HookExecutor
NewHookExecutor 创建钩子执行器
func (*HookExecutor) ExecuteConnectionEndHooks ¶
func (he *HookExecutor) ExecuteConnectionEndHooks(ctx context.Context, conn types.Connection, duration time.Duration) error
ExecuteConnectionEndHooks 执行连接结束钩子
func (*HookExecutor) ExecuteConnectionStartHooks ¶
func (he *HookExecutor) ExecuteConnectionStartHooks(ctx context.Context, conn types.Connection) error
ExecuteConnectionStartHooks 执行连接开始钩子
func (*HookExecutor) ExecuteDataProcessHooks ¶
func (he *HookExecutor) ExecuteDataProcessHooks(ctx context.Context, data []byte, direction types.PacketDirection) ([]byte, error)
ExecuteDataProcessHooks 执行数据处理钩子
func (*HookExecutor) ExecuteRequestHooks ¶
func (he *HookExecutor) ExecuteRequestHooks(ctx context.Context, interceptCtx *InterceptContext) (*InterceptResult, error)
ExecuteRequestHooks 执行请求钩子
func (*HookExecutor) ExecuteResponseHooks ¶
func (he *HookExecutor) ExecuteResponseHooks(ctx context.Context, interceptCtx *InterceptContext) (*InterceptResult, error)
ExecuteResponseHooks 执行响应钩子
func (*HookExecutor) ExecuteWebSocketMessageHooks ¶
func (he *HookExecutor) ExecuteWebSocketMessageHooks(ctx context.Context, wsCtx *WebSocketContext) (*InterceptResult, error)
ExecuteWebSocketMessageHooks 执行WebSocket消息拦截钩子
func (*HookExecutor) GetHookStats ¶
func (he *HookExecutor) GetHookStats() map[string]interface{}
GetHookStats 获取钩子统计信息
type InterceptContext ¶
type InterceptContext struct {
Request *http.Request
Response *http.Response
Connection types.Connection
Timestamp time.Time
RequestBody []byte
ResponseBody []byte
RequestHeaders http.Header
ResponseHeaders http.Header
Metadata map[string]interface{}
}
InterceptContext 拦截上下文,包含请求处理所需的所有信息
type InterceptResult ¶
type InterceptResult struct {
// Continue 是否继续处理
Continue bool
// Modified 是否修改了请求/响应
Modified bool
// Message 处理消息
Message string
// Error 错误信息
Error error
// Metadata 元数据
Metadata map[string]interface{}
}
InterceptResult 拦截结果
type InterceptorType ¶
type InterceptorType int
InterceptorType 拦截器类型
const ( // TypeRequest 请求拦截器 TypeRequest InterceptorType = iota // TypeResponse 响应拦截器 TypeResponse // TypeConnection 连接拦截器 TypeConnection // TypeData 数据处理器 TypeData )
type Logger ¶
type Logger interface {
Info(msg string, args ...interface{})
Error(msg string, args ...interface{})
Debug(msg string, args ...interface{})
Warn(msg string, args ...interface{})
}
Logger 插件日志接口
type ManagerConfig ¶
type ManagerConfig struct {
PluginsDir string `json:"plugins_dir"`
ConfigDir string `json:"config_dir"`
AutoLoad bool `json:"auto_load"`
LoadTimeout time.Duration `json:"load_timeout"`
EnableHotReload bool `json:"enable_hot_reload"`
WatchInterval time.Duration `json:"watch_interval"`
}
ManagerConfig 管理器配置
type MetricsCollector ¶
type MetricsCollector struct {
// contains filtered or unexported fields
}
MetricsCollector 指标收集器
func (*MetricsCollector) Get ¶
func (mc *MetricsCollector) Get(key string) (interface{}, bool)
Get 获取指标
func (*MetricsCollector) GetAll ¶
func (mc *MetricsCollector) GetAll() map[string]interface{}
GetAll 获取所有指标
func (*MetricsCollector) Increment ¶
func (mc *MetricsCollector) Increment(key string)
Increment 递增指标
func (*MetricsCollector) Set ¶
func (mc *MetricsCollector) Set(key string, value interface{})
Set 设置指标
type Plugin ¶
type Plugin interface {
// GetInfo 获取插件信息
GetInfo() PluginInfo
// Initialize 初始化插件
Initialize(ctx context.Context, config PluginConfig) error
// Start 启动插件
Start(ctx context.Context) error
// Stop 停止插件
Stop(ctx context.Context) error
// IsEnabled 检查插件是否启用
IsEnabled() bool
// GetPriority 获取插件优先级(数字越小优先级越高)
GetPriority() int
}
Plugin 插件主接口
type PluginAPI ¶
type PluginAPI interface {
// GetLogger 获取日志器
GetLogger(pluginName string) Logger
// GetConfig 获取应用配置
GetConfig() types.Config
// SendNotification 发送通知
SendNotification(title, message string) error
// GetMetrics 获取指标
GetMetrics() map[string]interface{}
// StoreData 存储数据
StoreData(key string, value interface{}) error
// GetData 获取数据
GetData(key string) (interface{}, error)
}
PluginAPI 插件API接口,提供给插件使用的应用能力
type PluginConfig ¶
type PluginConfig struct {
Enabled bool `json:"enabled"`
Priority int `json:"priority"`
Settings map[string]interface{} `json:"settings"`
Whitelist []string `json:"whitelist,omitempty"`
Blacklist []string `json:"blacklist,omitempty"`
}
PluginConfig 插件配置
type PluginInfo ¶
type PluginInfo struct {
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Author string `json:"author"`
Category string `json:"category"`
}
PluginInfo 插件基本信息
type PluginLogger ¶
type PluginLogger struct {
// contains filtered or unexported fields
}
PluginLogger 插件专用日志器
func (*PluginLogger) Debug ¶
func (pl *PluginLogger) Debug(msg string, args ...interface{})
Debug 调试日志
func (*PluginLogger) Error ¶
func (pl *PluginLogger) Error(msg string, args ...interface{})
Error 错误日志
type PluginManager ¶
type PluginManager struct {
// contains filtered or unexported fields
}
PluginManager 插件管理器
func NewPluginManager ¶
func NewPluginManager(api PluginAPI, logger types.Logger, config ManagerConfig) *PluginManager
NewPluginManager 创建插件管理器
func (*PluginManager) GetConnectionInterceptors ¶
func (pm *PluginManager) GetConnectionInterceptors() []ConnectionInterceptor
GetConnectionInterceptors 获取连接拦截器
func (*PluginManager) GetDataProcessors ¶
func (pm *PluginManager) GetDataProcessors() []DataProcessor
GetDataProcessors 获取数据处理器
func (*PluginManager) GetPluginList ¶
func (pm *PluginManager) GetPluginList() map[string]*PluginMetadata
GetPluginList 获取插件列表
func (*PluginManager) GetRequestInterceptors ¶
func (pm *PluginManager) GetRequestInterceptors() []RequestInterceptor
GetRequestInterceptors 获取请求拦截器
func (*PluginManager) GetResponseInterceptors ¶
func (pm *PluginManager) GetResponseInterceptors() []ResponseInterceptor
GetResponseInterceptors 获取响应拦截器
func (*PluginManager) GetWebSocketInterceptors ¶
func (pm *PluginManager) GetWebSocketInterceptors() []WebSocketInterceptor
GetWebSocketInterceptors 获取WebSocket拦截器
func (*PluginManager) RegisterFactory ¶
func (pm *PluginManager) RegisterFactory(name string, factory PluginFactory)
RegisterFactory 注册插件工厂
func (*PluginManager) StartPlugins ¶
func (pm *PluginManager) StartPlugins() error
StartPlugins 启动所有插件
type PluginMetadata ¶
type PluginMetadata struct {
Info PluginInfo `json:"info"`
Config PluginConfig `json:"config"`
FilePath string `json:"file_path"`
Factory PluginFactory `json:"-"`
}
PluginMetadata 插件元数据
type RequestInterceptor ¶
type RequestInterceptor interface {
Plugin
// InterceptRequest 拦截请求
InterceptRequest(ctx context.Context, interceptCtx *InterceptContext) (*InterceptResult, error)
}
RequestInterceptor 请求拦截器接口
type ResponseInterceptor ¶
type ResponseInterceptor interface {
Plugin
// InterceptResponse 拦截响应
InterceptResponse(ctx context.Context, interceptCtx *InterceptContext) (*InterceptResult, error)
}
ResponseInterceptor 响应拦截器接口
type SecurityConfig ¶
type SecurityConfig struct {
// 允许插件访问的功能
AllowedAPIs []string `json:"allowed_apis"`
// 插件沙箱模式
SandboxMode bool `json:"sandbox_mode"`
// 资源限制
MaxMemoryMB int `json:"max_memory_mb"`
MaxCPUTime int `json:"max_cpu_time_seconds"`
// 签名验证
RequireSignature bool `json:"require_signature"`
TrustedKeys []string `json:"trusted_keys"`
}
SecurityConfig 安全配置
type WebSocketContext ¶
type WebSocketContext struct {
Connection types.Connection
Request *http.Request // WebSocket升级请求
MessageType WebSocketMessageType // 消息类型
Message []byte // 消息内容
Direction WebSocketDirection // 消息方向
Timestamp time.Time
Metadata map[string]interface{}
}
WebSocketContext WebSocket拦截上下文
type WebSocketDirection ¶
type WebSocketDirection int
WebSocketDirection WebSocket消息方向
const ( // ClientToServer 客户端到服务器 ClientToServer WebSocketDirection = iota // ServerToClient 服务器到客户端 ServerToClient )
type WebSocketInterceptor ¶
type WebSocketInterceptor interface {
Plugin
// InterceptWebSocketMessage 拦截WebSocket消息
InterceptWebSocketMessage(ctx context.Context, interceptCtx *WebSocketContext) (*InterceptResult, error)
}
WebSocketInterceptor WebSocket拦截器接口
type WebSocketMessageType ¶
type WebSocketMessageType int
WebSocketMessageType WebSocket消息类型
const ( // TextMessage 文本消息 TextMessage WebSocketMessageType = iota // BinaryMessage 二进制消息 BinaryMessage // CloseMessage 关闭消息 CloseMessage // PingMessage Ping消息 PingMessage // PongMessage Pong消息 PongMessage )