Documentation
¶
Index ¶
- func IsErrorSeverity(err error, severity ErrorSeverity) bool
- func IsErrorType(err error, errType ErrorType) bool
- func IsPluginError(err error) bool
- type APIDoc
- type Configurable
- type DataProcessorPlugin
- type Debuggable
- type Documentable
- type Documentation
- type Error
- type ErrorSeverity
- type ErrorType
- type Event
- type EventHandlerPlugin
- type Example
- type HTTPHandlerPlugin
- type HealthStatus
- type IsolationConfig
- type Loggable
- type MetricsCollector
- type Monitorable
- type Parameter
- type Plugin
- type PluginConfig
- type PluginDependency
- type PluginError
- func GetPluginError(err error) (*PluginError, bool)
- func NewConfigError(pluginID string, message string, cause error) *PluginError
- func NewDependencyError(pluginID string, message string, cause error) *PluginError
- func NewInitError(pluginID string, message string, cause error) *PluginError
- func NewPluginError(pluginID string, errType ErrorType, severity ErrorSeverity, code string, ...) *PluginError
- func NewResourceError(pluginID string, message string, cause error) *PluginError
- func NewStartError(pluginID string, message string, cause error) *PluginError
- func NewStopError(pluginID string, message string, cause error) *PluginError
- func NewTimeoutError(pluginID string, message string, cause error) *PluginError
- func NewValidationError(pluginID string, message string, cause error) *PluginError
- type PluginEvent
- type PluginInfo
- type PluginLocation
- type PluginMetadata
- type PluginState
- type PluginStatus
- type Reference
- type SecurityPlugin
- type ServicePlugin
- type StoragePlugin
- type Traceable
- type UIPlugin
- type UIResource
- type UIRoute
- type VersionInfo
- type Versionable
- type Watcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsErrorSeverity ¶
func IsErrorSeverity(err error, severity ErrorSeverity) bool
IsErrorSeverity 检查错误是否为指定严重程度
Types ¶
type APIDoc ¶
type APIDoc struct {
Name string // API名称
Description string // API描述
Parameters []Parameter // 参数
Returns []Parameter // 返回值
Errors []Error // 错误
}
APIDoc 定义了API文档
type Configurable ¶
type Configurable interface {
// UpdateConfig 更新插件配置
// ctx: 上下文
// config: 新的配置
// 返回: 更新过程中的错误
UpdateConfig(ctx context.Context, config map[string]interface{}) error
// GetConfig 获取当前配置
// 返回: 当前配置
GetConfig() map[string]interface{}
// ValidateConfig 验证配置
// config: 待验证的配置
// 返回: 验证结果和错误信息
ValidateConfig(config map[string]interface{}) (bool, error)
}
Configurable 定义了可配置的插件能力 实现此接口的插件支持动态配置更新
type DataProcessorPlugin ¶
type DataProcessorPlugin interface {
Plugin // 继承基础插件接口
// ProcessData 处理数据
// ctx: 上下文
// data: 输入数据
// 返回: 处理后的数据和错误
ProcessData(ctx context.Context, data interface{}) (interface{}, error)
// GetSupportedDataTypes 返回支持的数据类型
// 返回: 支持的数据类型列表
GetSupportedDataTypes() []string
}
DataProcessorPlugin 定义了数据处理插件的接口 数据处理插件提供数据转换、分析、过滤等功能
type Debuggable ¶
type Debuggable interface {
// EnableDebug 启用调试
// level: 调试级别
// 返回: 错误
EnableDebug(level int) error
// DisableDebug 禁用调试
// 返回: 错误
DisableDebug() error
// GetDebugInfo 获取调试信息
// 返回: 调试信息
GetDebugInfo() map[string]interface{}
}
Debuggable 定义了可调试的插件能力 实现此接口的插件支持调试功能
type Documentable ¶
type Documentable interface {
// GetDocumentation 获取文档
// 返回: 文档内容
GetDocumentation() Documentation
}
Documentable 定义了可文档化的插件能力 实现此接口的插件提供自文档功能
type Documentation ¶
type Documentation struct {
Overview string // 概述
Usage string // 使用说明
API map[string]APIDoc // API文档
Examples []Example // 示例
References []Reference // 参考资料
}
Documentation 定义了文档
type ErrorSeverity ¶
type ErrorSeverity string
ErrorSeverity 定义了错误严重程度
const ( ErrorSeverityInfo ErrorSeverity = "info" // 信息 ErrorSeverityWarning ErrorSeverity = "warning" // 警告 ErrorSeverityError ErrorSeverity = "error" // 错误 ErrorSeverityCritical ErrorSeverity = "critical" // 严重 ErrorSeverityFatal ErrorSeverity = "fatal" // 致命 )
预定义的错误严重程度
type ErrorType ¶
type ErrorType string
ErrorType 定义了错误类型
const ( ErrorTypePlugin ErrorType = "plugin" // 插件错误 ErrorTypeInit ErrorType = "init" // 初始化错误 ErrorTypeStart ErrorType = "start" // 启动错误 ErrorTypeStop ErrorType = "stop" // 停止错误 ErrorTypeConfig ErrorType = "config" // 配置错误 ErrorTypeDependency ErrorType = "dependency" // 依赖错误 ErrorTypeIsolation ErrorType = "isolation" // 隔离错误 ErrorTypeTimeout ErrorType = "timeout" // 超时错误 ErrorTypeResource ErrorType = "resource" // 资源错误 ErrorTypePermission ErrorType = "permission" // 权限错误 ErrorTypeValidation ErrorType = "validation" // 验证错误 ErrorTypeInternal ErrorType = "internal" // 内部错误 ErrorTypeExternal ErrorType = "external" // 外部错误 ErrorTypeUnknown ErrorType = "unknown" // 未知错误 )
预定义的错误类型
type Event ¶
type Event struct {
Type string // 事件类型
Source string // 事件源
ID string // 事件ID
Timestamp time.Time // 时间戳
Data map[string]interface{} // 事件数据
}
Event 定义了事件
type EventHandlerPlugin ¶
type EventHandlerPlugin interface {
Plugin // 继承基础插件接口
// HandleEvent 处理事件
// ctx: 上下文
// event: 事件
// 返回: 处理结果和错误
HandleEvent(ctx context.Context, event Event) (interface{}, error)
// GetSupportedEventTypes 返回支持的事件类型
// 返回: 支持的事件类型列表
GetSupportedEventTypes() []string
}
EventHandlerPlugin 定义了事件处理器插件的接口 事件处理器插件提供事件处理功能
type Example ¶
type Example struct {
Title string // 示例标题
Description string // 示例描述
Code string // 示例代码
Output string // 示例输出
}
Example 定义了示例
type HTTPHandlerPlugin ¶
type HTTPHandlerPlugin interface {
Plugin // 继承基础插件接口
// GetHTTPHandler 返回HTTP处理器
// 返回: HTTP处理器和错误
GetHTTPHandler() (http.Handler, error)
// GetBasePath 返回基础路径
// 返回: 处理器的基础路径
GetBasePath() string
}
HTTPHandlerPlugin 定义了HTTP处理器插件的接口 HTTP处理器插件提供HTTP请求处理功能
type HealthStatus ¶
type HealthStatus struct {
Status string // 状态: healthy, degraded, unhealthy
Details map[string]interface{} // 详细信息
LastChecked time.Time // 最后检查时间
}
HealthStatus 定义了插件的健康状态
type IsolationConfig ¶
type IsolationConfig struct {
Level string // 隔离级别: none, basic, strict, complete
Resources map[string]int64 // 资源限制: memory, cpu, etc.
Timeout time.Duration // 操作超时时间
WorkingDir string // 工作目录
Environment map[string]string // 环境变量
}
IsolationConfig 定义了插件的隔离配置
type Loggable ¶
type Loggable interface {
// Log 记录日志
// level: 日志级别
// msg: 日志消息
// fields: 日志字段
Log(level string, msg string, fields map[string]interface{})
// SetLogLevel 设置日志级别
// level: 日志级别
SetLogLevel(level string)
// GetLogLevel 获取日志级别
// 返回: 当前日志级别
GetLogLevel() string
}
Loggable 定义了可记录日志的插件能力 实现此接口的插件支持结构化日志记录
type MetricsCollector ¶
type MetricsCollector interface {
// CollectMetric 收集指标
// name: 指标名称
// value: 指标值
// labels: 标签
CollectMetric(name string, value float64, labels map[string]string) error
}
MetricsCollector 定义了指标收集器接口
type Monitorable ¶
type Monitorable interface {
// GetMetrics 获取指标
// 返回: 指标数据
GetMetrics() map[string]interface{}
// RegisterMetricsCollector 注册指标收集器
// collector: 指标收集器
// 返回: 错误
RegisterMetricsCollector(collector MetricsCollector) error
}
Monitorable 定义了可监控的插件能力 实现此接口的插件支持监控功能
type Parameter ¶
type Parameter struct {
Name string // 参数名称
Type string // 参数类型
Description string // 参数描述
Required bool // 是否必需
Default interface{} // 默认值
}
Parameter 定义了参数
type Plugin ¶
type Plugin interface {
// GetInfo 返回插件的基本信息
GetInfo() PluginInfo
// Init 初始化插件
// ctx: 上下文,可用于超时控制和取消操作
// config: 插件配置
// 返回: 初始化过程中的错误
Init(ctx context.Context, config PluginConfig) error
// Start 启动插件
// ctx: 上下文,可用于超时控制和取消操作
// 返回: 启动过程中的错误
Start(ctx context.Context) error
// Stop 停止插件
// ctx: 上下文,可用于超时控制和取消操作
// 返回: 停止过程中的错误
Stop(ctx context.Context) error
// HealthCheck 执行健康检查
// ctx: 上下文,可用于超时控制和取消操作
// 返回: 健康状态和检查过程中的错误
HealthCheck(ctx context.Context) (HealthStatus, error)
}
Plugin 定义了所有插件必须实现的基础接口 这是插件系统的核心接口,所有插件都必须实现这个接口
type PluginConfig ¶
type PluginConfig struct {
// 基本配置
ID string // 插件ID
Enabled bool // 是否启用
LogLevel string // 日志级别
// 运行时配置
AutoStart bool // 是否自动启动
AutoRestart bool // 是否自动重启
// 隔离配置
Isolation IsolationConfig // 隔离配置
// 自定义配置
Settings map[string]interface{} // 自定义设置,插件特定的配置项
}
PluginConfig 定义了插件的配置
type PluginDependency ¶
type PluginDependency struct {
ID string // 依赖的插件ID
Version string // 依赖的插件版本要求(语义化版本表达式)
Optional bool // 是否为可选依赖
}
PluginDependency 定义了插件的依赖关系
type PluginError ¶
type PluginError struct {
Type ErrorType // 错误类型
Severity ErrorSeverity // 错误严重程度
Code string // 错误代码
Message string // 错误消息
PluginID string // 插件ID
Details map[string]interface{} // 错误详情
Cause error // 原因
}
PluginError 定义了插件错误
func NewConfigError ¶
func NewConfigError(pluginID string, message string, cause error) *PluginError
NewConfigError 创建配置错误
func NewDependencyError ¶
func NewDependencyError(pluginID string, message string, cause error) *PluginError
NewDependencyError 创建依赖错误
func NewInitError ¶
func NewInitError(pluginID string, message string, cause error) *PluginError
NewInitError 创建初始化错误
func NewPluginError ¶
func NewPluginError(pluginID string, errType ErrorType, severity ErrorSeverity, code string, message string, cause error) *PluginError
NewPluginError 创建一个新的插件错误
func NewResourceError ¶
func NewResourceError(pluginID string, message string, cause error) *PluginError
NewResourceError 创建资源错误
func NewStartError ¶
func NewStartError(pluginID string, message string, cause error) *PluginError
NewStartError 创建启动错误
func NewStopError ¶
func NewStopError(pluginID string, message string, cause error) *PluginError
NewStopError 创建停止错误
func NewTimeoutError ¶
func NewTimeoutError(pluginID string, message string, cause error) *PluginError
NewTimeoutError 创建超时错误
func NewValidationError ¶
func NewValidationError(pluginID string, message string, cause error) *PluginError
NewValidationError 创建验证错误
func (*PluginError) WithDetails ¶
func (e *PluginError) WithDetails(details map[string]interface{}) *PluginError
WithDetails 添加错误详情
type PluginEvent ¶
type PluginEvent struct {
Type string // 事件类型: loaded, unloaded, started, stopped, error
PluginID string // 插件ID
Timestamp time.Time // 时间戳
Data map[string]interface{} // 事件数据
}
PluginEvent 定义了插件事件
type PluginInfo ¶
type PluginInfo struct {
ID string // 插件唯一标识符
Name string // 插件名称
Version string // 插件版本
Description string // 插件描述
Author string // 插件作者
License string // 插件许可证
Tags []string // 插件标签,用于分类和筛选
Capabilities map[string]bool // 插件能力,表示插件支持的功能
Dependencies []PluginDependency // 插件依赖,表示插件依赖的其他插件
}
PluginInfo 包含插件的基本信息
type PluginLocation ¶
type PluginLocation struct {
// 位置类型: local, remote, registry
Type string
// 路径
Path string
// URL
URL string
// 版本
Version string
}
PluginLocation 插件位置
type PluginMetadata ¶
type PluginMetadata struct {
// 插件ID
ID string
// 插件名称
Name string
// 插件版本
Version string
// 插件描述
Description string
// 插件作者
Author string
// 插件许可证
License string
// 插件标签
Tags []string
// 插件能力
Capabilities map[string]bool
// 插件依赖
Dependencies []PluginDependency
// 插件位置
Location PluginLocation
// 插件签名
Signature string
// 注册时间
Timestamp time.Time
}
PluginMetadata 插件元数据
type PluginState ¶
type PluginState string
PluginState 表示插件的状态
const ( PluginStateUnknown PluginState = "unknown" // 未知状态 PluginStateDiscovered PluginState = "discovered" // 已发现 PluginStateRegistered PluginState = "registered" // 已注册 PluginStateLoaded PluginState = "loaded" // 已加载 PluginStateInitialized PluginState = "initialized" // 已初始化 PluginStateStarting PluginState = "starting" // 启动中 PluginStateRunning PluginState = "running" // 运行中 PluginStateStopping PluginState = "stopping" // 停止中 PluginStateStopped PluginState = "stopped" // 已停止 PluginStateFailed PluginState = "failed" // 失败 PluginStateUnloading PluginState = "unloading" // 卸载中 PluginStateUnloaded PluginState = "unloaded" // 已卸载 )
预定义的插件状态
const PluginStateInitializing PluginState = "initializing"
PluginStateInitializing 初始化中状态
type PluginStatus ¶
type PluginStatus struct {
ID string // 插件ID
State PluginState // 状态
Health HealthStatus // 健康状态
StartTime time.Time // 启动时间
StopTime time.Time // 停止时间
Error string // 错误信息
Statistics map[string]interface{} // 统计信息
}
PluginStatus 定义了插件的状态信息
type SecurityPlugin ¶
type SecurityPlugin interface {
Plugin // 继承基础插件接口
// ValidateRequest 验证请求
// ctx: 上下文
// request: 请求对象
// 返回: 验证结果和错误
ValidateRequest(ctx context.Context, request interface{}) (bool, error)
// EncryptData 加密数据
// ctx: 上下文
// data: 待加密数据
// 返回: 加密后的数据和错误
EncryptData(ctx context.Context, data []byte) ([]byte, error)
// DecryptData 解密数据
// ctx: 上下文
// data: 待解密数据
// 返回: 解密后的数据和错误
DecryptData(ctx context.Context, data []byte) ([]byte, error)
}
SecurityPlugin 定义了安全插件的接口 安全插件提供认证、授权、加密等安全相关功能
type ServicePlugin ¶
type ServicePlugin interface {
Plugin // 继承基础插件接口
// GetService 返回插件提供的服务实例
// 返回值是一个通用接口,调用方需要根据插件类型进行类型断言
GetService() (interface{}, error)
// RegisterHandler 注册服务处理器
// path: 服务路径
// handler: 处理器实例
RegisterHandler(path string, handler interface{}) error
}
ServicePlugin 定义了服务类型插件的接口 服务插件提供可调用的服务功能,如API服务、数据处理服务等
type StoragePlugin ¶
type StoragePlugin interface {
Plugin // 继承基础插件接口
// Store 存储数据
// ctx: 上下文
// key: 键
// value: 值
// 返回: 错误
Store(ctx context.Context, key string, value []byte) error
// Retrieve 检索数据
// ctx: 上下文
// key: 键
// 返回: 值和错误
Retrieve(ctx context.Context, key string) ([]byte, error)
// Delete 删除数据
// ctx: 上下文
// key: 键
// 返回: 错误
Delete(ctx context.Context, key string) error
// List 列出键
// ctx: 上下文
// prefix: 前缀
// 返回: 键列表和错误
List(ctx context.Context, prefix string) ([]string, error)
}
StoragePlugin 定义了存储插件的接口 存储插件提供数据存储功能
type Traceable ¶
type Traceable interface {
// StartSpan 开始一个追踪span
// ctx: 上下文
// operationName: 操作名称
// 返回: 新的上下文和span
StartSpan(ctx context.Context, operationName string) (context.Context, interface{})
// FinishSpan 结束一个追踪span
// span: 要结束的span
FinishSpan(span interface{})
// AddSpanTag 添加span标签
// span: 目标span
// key: 标签键
// value: 标签值
AddSpanTag(span interface{}, key string, value interface{})
}
Traceable 定义了可追踪的插件能力 实现此接口的插件支持分布式追踪
type UIPlugin ¶
type UIPlugin interface {
Plugin // 继承基础插件接口
// GetUIResources 返回插件提供的UI资源
// 如CSS、JavaScript、图片等静态资源
GetUIResources() ([]UIResource, error)
// GetUIRoutes 返回插件提供的UI路由
// 定义了插件UI组件如何集成到主应用的路由系统
GetUIRoutes() ([]UIRoute, error)
}
UIPlugin 定义了UI类型插件的接口 UI插件提供用户界面组件,可以集成到主应用的界面中
type UIResource ¶
UIResource 定义了UI资源
type UIRoute ¶
type UIRoute struct {
Path string // 路由路径
Component string // 组件名称
Title string // 页面标题
Icon string // 图标
Permissions []string // 所需权限
Children []UIRoute // 子路由
}
UIRoute 定义了UI路由
type VersionInfo ¶
type VersionInfo struct {
Version string // 版本号
BuildTime string // 构建时间
GitCommit string // Git提交哈希
APIVersions []string // 支持的API版本
}
VersionInfo 定义了版本信息
type Versionable ¶
type Versionable interface {
// GetVersion 获取版本信息
// 返回: 版本信息
GetVersion() VersionInfo
// CheckCompatibility 检查兼容性
// requiredVersion: 所需版本
// 返回: 是否兼容
CheckCompatibility(requiredVersion string) bool
}
Versionable 定义了可版本化的插件能力 实现此接口的插件支持版本管理