plugins

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2025 License: Apache-2.0 Imports: 7 Imported by: 18

Documentation

Overview

Package plugins provides a plugin system for extending application functionality. 包 plugins 提供了一个用于扩展应用程序功能的插件系统。

Index

Constants

View Source
const (
	// PriorityLow indicates minimal impact events that can be processed later
	// PriorityLow 表示影响极小的事件,可以稍后处理。
	PriorityLow = 0
	// PriorityNormal indicates standard events requiring routine processing
	// PriorityNormal 表示需要常规处理的标准事件。
	PriorityNormal = 1
	// PriorityHigh indicates important events needing prompt attention
	// PriorityHigh 表示需要立即关注的重要事件。
	PriorityHigh = 2
	// PriorityCritical indicates urgent events requiring immediate handling
	// PriorityCritical 表示需要立即处理的紧急事件。
	PriorityCritical = 3
)

Priority levels for plugin events 插件事件的优先级级别

View Source
const (
	// EventPluginInitializing indicates the plugin is starting initialization.
	// Triggered when plugin begins loading resources and establishing connections.
	// EventPluginInitializing 表示插件开始初始化。
	// 当插件开始加载资源并建立连接时触发。
	EventPluginInitializing = "plugin.initializing"

	// EventPluginInitialized indicates the plugin completed initialization.
	// Triggered when all resources are loaded and connections established.
	// EventPluginInitialized 表示插件已完成初始化。
	// 当所有资源加载完成且连接建立后触发。
	EventPluginInitialized = "plugin.initialized"

	// EventPluginStarting indicates the plugin is beginning its operations.
	// Triggered when core functionality is about to begin.
	// EventPluginStarting 表示插件开始执行操作。
	// 当核心功能即将启动时触发。
	EventPluginStarting = "plugin.starting"

	// EventPluginStarted indicates the plugin is fully operational.
	// Triggered when all systems are running and ready to handle requests.
	// EventPluginStarted 表示插件已完全投入运行。
	// 当所有系统都已运行并准备好处理请求时触发。
	EventPluginStarted = "plugin.started"

	// EventPluginStopping indicates the plugin is beginning shutdown.
	// Triggered when shutdown command is received and cleanup begins.
	// EventPluginStopping 表示插件开始关闭。
	// 当收到关闭命令并开始清理工作时触发。
	EventPluginStopping = "plugin.stopping"

	// EventPluginStopped indicates the plugin completed shutdown.
	// Triggered when all resources are released and connections closed.
	// EventPluginStopped 表示插件已完成关闭。
	// 当所有资源释放且连接关闭后触发。
	EventPluginStopped = "plugin.stopped"
)

Plugin lifecycle event types for comprehensive system monitoring 用于全面系统监控的插件生命周期事件类型

View Source
const (
	// EventHealthCheckStarted indicates a health check operation has begun.
	// Triggered when the health check routine starts executing.
	// EventHealthCheckStarted 表示健康检查操作已开始。
	// 当健康检查程序开始执行时触发。
	EventHealthCheckStarted = "health.check.started"

	// EventHealthCheckRunning indicates a health check is in progress.
	// Triggered during the execution of health check procedures.
	// EventHealthCheckRunning 表示健康检查正在进行中。
	// 当健康检查流程执行期间触发。
	EventHealthCheckRunning = "health.check.running"

	// EventHealthCheckDone indicates a health check has completed.
	// Triggered when all health check procedures have finished.
	// EventHealthCheckDone 表示健康检查已完成。
	// 当所有健康检查流程完成后触发。
	EventHealthCheckDone = "health.check.done"

	// EventHealthStatusOK indicates the plugin is healthy.
	// Triggered when all health metrics are within normal ranges.
	// EventHealthStatusOK 表示插件状态健康。
	// 当所有健康指标都在正常范围内时触发。
	EventHealthStatusOK = "health.status.ok"

	// EventHealthStatusWarning indicates potential health issues.
	// Triggered when health metrics show concerning trends.
	// EventHealthStatusWarning 表示插件可能存在健康问题。
	// 当健康指标显示出令人担忧的趋势时触发。
	EventHealthStatusWarning = "health.status.warning"

	// EventHealthStatusCritical indicates severe health issues.
	// Triggered when health metrics exceed critical thresholds.
	// EventHealthStatusCritical 表示插件存在严重健康问题。
	// 当健康指标超过临界阈值时触发。
	EventHealthStatusCritical = "health.status.critical"

	// EventHealthStatusUnknown indicates health status cannot be determined.
	// Triggered when health check procedures fail to complete.
	// EventHealthStatusUnknown 表示无法确定插件的健康状态。
	// 当健康检查流程未能完成时触发。
	EventHealthStatusUnknown = "health.status.unknown"

	// EventHealthMetricsChanged indicates a change in health metrics.
	// Triggered when monitored metrics show significant changes.
	// EventHealthMetricsChanged 表示健康指标发生了变化。
	// 当监控的指标显示出显著变化时触发。
	EventHealthMetricsChanged = "health.metrics.changed"

	// EventHealthThresholdHit indicates metrics exceeded defined thresholds.
	// Triggered when health metrics cross warning or critical levels.
	// EventHealthThresholdHit 表示指标超过了定义的阈值。
	// 当健康指标越过警告或临界水平时触发。
	EventHealthThresholdHit = "health.metrics.threshold"

	// EventHealthStatusChanged indicates overall health status change.
	// Triggered when the aggregate health status transitions.
	// EventHealthStatusChanged 表示整体健康状态发生了变化。
	// 当综合健康状态发生转变时触发。
	EventHealthStatusChanged = "health.status.changed"

	// EventHealthCheckFailed indicates health check operation failure.
	// Triggered when health check procedures encounter errors.
	// EventHealthCheckFailed 表示健康检查操作失败。
	// 当健康检查流程遇到错误时触发。
	EventHealthCheckFailed = "health.check.failed"
)

Health check event types for monitoring plugin health status 用于监控插件健康状态的健康检查事件类型

View Source
const (
	// EventResourceExhausted indicates critical resource depletion.
	// Triggered when system resources reach critical levels.
	// EventResourceExhausted 表示关键资源耗尽。
	// 当系统资源达到临界水平时触发。
	EventResourceExhausted = "resource.exhausted"

	// EventPerformanceDegraded indicates performance deterioration.
	// Triggered when system performance metrics decline significantly.
	// EventPerformanceDegraded 表示性能下降。
	// 当系统性能指标显著下降时触发。
	EventPerformanceDegraded = "performance.degraded"
)

Resource event types for monitoring system resources 用于监控系统资源的资源事件类型

View Source
const (
	// EventConfigurationChanged indicates configuration update initiation.
	// Triggered when new configuration is being applied.
	// EventConfigurationChanged 表示配置更新开始。
	// 当新配置正在应用时触发。
	EventConfigurationChanged = "config.changed"

	// EventConfigurationInvalid indicates invalid configuration.
	// Triggered when configuration validation fails.
	// EventConfigurationInvalid 表示配置无效。
	// 当配置验证失败时触发。
	EventConfigurationInvalid = "config.invalid"

	// EventConfigurationApplied indicates successful configuration update.
	// Triggered when new configuration is active and verified.
	// EventConfigurationApplied 表示配置更新成功。
	// 当新配置生效并通过验证时触发。
	EventConfigurationApplied = "config.applied"
)

Configuration event types for managing plugin configuration 用于管理插件配置的配置事件类型

View Source
const (
	// EventDependencyMissing indicates missing required dependency.
	// Triggered when required plugin or resource is unavailable.
	// EventDependencyMissing 表示缺少必需的依赖项。
	// 当必需的插件或资源不可用时触发。
	EventDependencyMissing = "dependency.missing"

	// EventDependencyStatusChanged indicates dependency state change.
	// Triggered when dependent plugin changes operational state.
	// EventDependencyStatusChanged 表示依赖项状态发生变化。
	// 当依赖的插件操作状态发生改变时触发。
	EventDependencyStatusChanged = "dependency.status.changed"

	// EventDependencyError indicates dependency-related error.
	// Triggered when dependency fails or becomes unstable.
	// EventDependencyError 表示发生与依赖项相关的错误。
	// 当依赖项失败或变得不稳定时触发。
	EventDependencyError = "dependency.error"
)

Dependency event types for managing plugin dependencies 用于管理插件依赖项的依赖事件类型

View Source
const (
	// EventUpgradeAvailable indicates new version availability.
	// Triggered when update check finds newer version.
	// EventUpgradeAvailable 表示有新版本可用。
	// 当更新检查发现较新版本时触发。
	EventUpgradeAvailable = "upgrade.available"

	// EventUpgradeInitiated indicates upgrade process start.
	// Triggered when upgrade sequence begins.
	// EventUpgradeInitiated 表示升级过程开始。
	// 当升级流程启动时触发。
	EventUpgradeInitiated = "upgrade.initiated"

	// EventUpgradeValidating indicates upgrade validation.
	// Triggered when validating system state before upgrade.
	// EventUpgradeValidating 表示正在进行升级验证。
	// 当在升级前验证系统状态时触发。
	EventUpgradeValidating = "upgrade.validating"

	// EventUpgradeInProgress indicates that the upgrade process is ongoing.
	// Triggered when the upgrade process is in progress.
	// EventUpgradeInProgress 表示升级过程正在进行中。
	// 当升级过程正在进行时触发。
	EventUpgradeInProgress = "upgrade.in_progress"

	// EventUpgradeCompleted indicates successful upgrade.
	// Triggered when new version is installed and verified.
	// EventUpgradeCompleted 表示升级成功。
	// 当新版本安装并验证通过后触发。
	EventUpgradeCompleted = "upgrade.completed"

	// EventUpgradeFailed indicates failed upgrade attempt.
	// Triggered when upgrade process encounters error.
	// EventUpgradeFailed 表示升级尝试失败。
	// 当升级过程遇到错误时触发。
	EventUpgradeFailed = "upgrade.failed"

	// EventRollbackInitiated indicates version rollback start.
	// Triggered when rollback to previous version begins.
	// EventRollbackInitiated 表示版本回滚开始。
	// 当开始回滚到上一个版本时触发。
	EventRollbackInitiated = "rollback.initiated"

	// EventRollbackInProgress indicates that the rollback process is ongoing.
	// Triggered when the rollback process has started and is in progress.
	// EventRollbackInProgress 表示回滚过程正在进行中。
	// 当回滚过程已启动并正在进行时触发。
	EventRollbackInProgress = "rollback.in_progress"

	// EventRollbackCompleted indicates successful rollback.
	// Triggered when previous version is restored.
	// EventRollbackCompleted 表示回滚成功。
	// 当上一个版本恢复成功时触发。
	EventRollbackCompleted = "rollback.completed"

	// EventRollbackFailed indicates failed rollback attempt.
	// Triggered when unable to restore previous version.
	// EventRollbackFailed 表示回滚尝试失败。
	// 当无法恢复上一个版本时触发。
	EventRollbackFailed = "rollback.failed"
)

Upgrade event types for managing plugin versions 用于管理插件版本的升级事件类型

View Source
const (
	// EventSecurityViolation indicates security policy breach.
	// Triggered when security rules are violated.
	// EventSecurityViolation 表示违反了安全策略。
	// 当安全规则被违反时触发。
	EventSecurityViolation = "security.violation"

	// EventAuthenticationFailed indicates failed authentication.
	// Triggered when invalid credentials are used.
	// EventAuthenticationFailed 表示认证失败。
	// 当使用无效凭证时触发。
	EventAuthenticationFailed = "auth.failed"

	// EventAuthorizationDenied indicates unauthorized access.
	// Triggered when insufficient permissions are detected.
	// EventAuthorizationDenied 表示未授权访问。
	// 当检测到权限不足时触发。
	EventAuthorizationDenied = "auth.denied"
)

Security event types for monitoring security-related events 用于监控与安全相关事件的安全事件类型

View Source
const (
	// EventResourceCreated indicates new resource allocation.
	// Triggered when new resource is successfully created.
	// EventResourceCreated 表示新资源已分配。
	// 当新资源成功创建时触发。
	EventResourceCreated = "resource.created"

	// EventResourceModified indicates resource modification.
	// Triggered when existing resource is updated.
	// EventResourceModified 表示资源已修改。
	// 当现有资源被更新时触发。
	EventResourceModified = "resource.modified"

	// EventResourceDeleted indicates resource removal.
	// Triggered when resource is successfully deleted.
	// EventResourceDeleted 表示资源已删除。
	// 当资源成功删除时触发。
	EventResourceDeleted = "resource.deleted"

	// EventResourceUnavailable indicates resource access failure.
	// Triggered when resource becomes inaccessible.
	// EventResourceUnavailable 表示资源访问失败。
	// 当资源变得不可访问时触发。
	EventResourceUnavailable = "resource.unavailable"
)

Resource lifecycle event types 资源生命周期事件类型

View Source
const (
	// EventErrorOccurred indicates error detection.
	// Triggered when system encounters an error condition.
	// EventErrorOccurred 表示检测到错误。
	// 当系统遇到错误情况时触发。
	EventErrorOccurred = "error.occurred"

	// EventErrorResolved indicates error recovery.
	// Triggered when error condition is successfully resolved.
	// EventErrorResolved 表示错误已恢复。
	// 当错误情况成功解决时触发。
	EventErrorResolved = "error.resolved"

	// EventPanicRecovered indicates panic recovery.
	// Triggered when system recovers from panic condition.
	// EventPanicRecovered 表示从 panic 状态恢复。
	// 当系统从 panic 状态恢复时触发。
	EventPanicRecovered = "panic.recovered"
)

Error event types for error handling and recovery 用于错误处理和恢复的错误事件类型

View Source
const (
	// DefaultOrg is the default organization identifier
	// DefaultOrg 是默认的组织标识符
	DefaultOrg = "go-lynx"
	// ComponentType represents the plugin component type
	// ComponentType 表示插件组件类型
	ComponentType = "plugin"
)

ID format constants ID 格式常量

Variables

View Source
var (
	// ErrPluginNotFound indicates that a requested plugin could not be found in the system
	// This error occurs when attempting to access or operate on a non-existent plugin
	// ErrPluginNotFound 表示在系统中找不到请求的插件。
	// 当尝试访问或操作一个不存在的插件时会出现此错误。
	ErrPluginNotFound = errors.New("plugin not found")

	// ErrPluginAlreadyExists indicates an attempt to register a plugin with an ID that is already in use
	// This error helps maintain unique plugin identifiers across the system
	// ErrPluginAlreadyExists 表示尝试注册一个使用了已存在 ID 的插件。
	// 此错误有助于确保系统中插件标识符的唯一性。
	ErrPluginAlreadyExists = errors.New("plugin already exists")

	// ErrPluginNotInitialized indicates an attempt to use a plugin that hasn't been properly initialized
	// Operations on uninitialized plugins are not allowed to prevent undefined behavior
	// ErrPluginNotInitialized 表示尝试使用一个未正确初始化的插件。
	// 为避免未定义行为,不允许对未初始化的插件进行操作。
	ErrPluginNotInitialized = errors.New("plugin not initialized")

	// ErrPluginNotActive indicates an attempt to use a plugin that is not in the active state
	// The plugin must be in StatusActive to perform the requested operation
	// ErrPluginNotActive 表示尝试使用一个未处于活动状态的插件。
	// 插件必须处于活动状态才能执行请求的操作。
	ErrPluginNotActive = errors.New("plugin not active")

	// ErrPluginAlreadyActive indicates an attempt to start an already active plugin
	// Prevents duplicate activation of plugins
	// ErrPluginAlreadyActive 表示尝试启动一个已经处于活动状态的插件。
	// 用于防止插件被重复激活。
	ErrPluginAlreadyActive = errors.New("plugin already active")

	// ErrInvalidPluginID indicates that the provided plugin ID is invalid
	// Plugin IDs must follow specific formatting rules and be non-empty
	// ErrInvalidPluginID 表示提供的插件 ID 无效。
	// 插件 ID 必须遵循特定的格式规则且不能为空。
	ErrInvalidPluginID = errors.New("invalid plugin ID")

	// ErrInvalidPluginVersion indicates that the provided plugin version is invalid
	// Version strings must follow semantic versioning format
	// ErrInvalidPluginVersion 表示提供的插件版本无效。
	// 版本字符串必须遵循语义化版本格式。
	ErrInvalidPluginVersion = errors.New("invalid plugin version")

	// ErrInvalidPluginConfig indicates that the provided plugin configuration is invalid
	// Configuration must meet the plugin's specific requirements
	// ErrInvalidPluginConfig 表示提供的插件配置无效。
	// 配置必须满足插件的特定要求。
	ErrInvalidPluginConfig = errors.New("invalid plugin configuration")

	// ErrInvalidConfiguration indicates that the provided configuration is not of the expected type
	// This error occurs when attempting to configure a plugin with an incompatible configuration type
	// ErrInvalidConfiguration 表示提供的配置不是预期的类型。
	// 当尝试使用不兼容的配置类型来配置插件时会出现此错误。
	ErrInvalidConfiguration = errors.New("invalid configuration type")

	// ErrPluginDependencyNotMet indicates that one or more plugin dependencies are not satisfied
	// All required dependencies must be available and properly configured
	// ErrPluginDependencyNotMet 表示一个或多个插件依赖项未满足。
	// 所有必需的依赖项必须可用且已正确配置。
	ErrPluginDependencyNotMet = errors.New("plugin dependency not met")

	// ErrPluginUpgradeNotSupported indicates that the plugin does not support the requested upgrade operation
	// The plugin must implement the Upgradable interface and support the specific upgrade capability
	// ErrPluginUpgradeNotSupported 表示插件不支持请求的升级操作。
	// 插件必须实现 Upgradable 接口并支持特定的升级能力。
	ErrPluginUpgradeNotSupported = errors.New("plugin upgrade not supported")

	// ErrPluginUpgradeFailed indicates that the plugin upgrade process failed
	// Contains details about the specific failure in upgrade process
	// ErrPluginUpgradeFailed 表示插件升级过程失败。
	// 包含升级过程中具体失败的详细信息。
	ErrPluginUpgradeFailed = errors.New("plugin upgrade failed")

	// ErrPluginResourceNotFound indicates that a requested plugin resource is not available
	// The resource must be registered before it can be accessed
	// ErrPluginResourceNotFound 表示请求的插件资源不可用。
	// 资源必须先注册才能被访问。
	ErrPluginResourceNotFound = errors.New("plugin resource not found")

	// ErrPluginResourceInvalid indicates that a plugin resource is in an invalid state
	// The resource must be properly initialized and maintained
	// ErrPluginResourceInvalid 表示插件资源处于无效状态。
	// 资源必须正确初始化并维护。
	ErrPluginResourceInvalid = errors.New("plugin resource invalid")

	// ErrPluginOperationTimeout indicates that a plugin operation exceeded its time limit
	// Operations must complete within their specified timeout period
	// ErrPluginOperationTimeout 表示插件操作超过了其时间限制。
	// 操作必须在指定的超时时间内完成。
	ErrPluginOperationTimeout = errors.New("plugin operation timeout")

	// ErrPluginOperationCancelled indicates that a plugin operation was cancelled
	// The operation was terminated before completion, either by user request or system action
	// ErrPluginOperationCancelled 表示插件操作被取消。
	// 该操作在完成前被终止,可能是用户请求或系统操作导致的。
	ErrPluginOperationCancelled = errors.New("plugin operation cancelled")

	// ErrPluginHealthCheckFailed indicates that the plugin's health check failed
	// The plugin is in an unhealthy state and may need attention
	// ErrPluginHealthCheckFailed 表示插件的健康检查失败。
	// 插件处于不健康状态,可能需要关注。
	ErrPluginHealthCheckFailed = errors.New("plugin health check failed")

	// ErrPluginSecurityViolation indicates a security-related violation in the plugin
	// Security policies or constraints have been breached
	// ErrPluginSecurityViolation 表示插件中发生了与安全相关的违规行为。
	// 安全策略或约束已被违反。
	ErrPluginSecurityViolation = errors.New("plugin security violation")
)

Common error variables for plugin-related operations 插件相关操作的通用错误变量

Functions

func GeneratePluginID

func GeneratePluginID(org, name, version string) string

GeneratePluginID generates a standard format plugin ID GeneratePluginID 生成标准格式的插件 ID

func GetPluginMainVersion

func GetPluginMainVersion(id string) (string, error)

GetPluginMainVersion extracts the main version number from a plugin ID GetPluginMainVersion 从插件 ID 中提取主版本号

func IsPluginVersionCompatible

func IsPluginVersionCompatible(v1, v2 string) bool

IsPluginVersionCompatible checks if two plugin versions are compatible IsPluginVersionCompatible 检查两个插件版本是否兼容

func ValidatePluginID

func ValidatePluginID(id string) error

ValidatePluginID validates the format of a plugin ID ValidatePluginID 验证插件 ID 的格式

Types

type BasePlugin

type BasePlugin struct {
	// contains filtered or unexported fields
}

BasePlugin provides a default implementation of the Plugin interface and common optional interfaces. It serves as a foundation for building custom plugins with standard functionality. BasePlugin 提供了 Plugin 接口和常见可选接口的默认实现。 它作为构建具有标准功能的自定义插件的基础。

func NewBasePlugin

func NewBasePlugin(id, name, description, version, confPrefix string, weight int) *BasePlugin

NewBasePlugin creates a new instance of BasePlugin with the provided metadata. This is the recommended way to initialize a new plugin implementation. NewBasePlugin 使用提供的元数据创建一个新的 BasePlugin 实例。 这是初始化新插件实现的推荐方式。

func (*BasePlugin) AddDependency

func (p *BasePlugin) AddDependency(dep Dependency)

AddDependency adds a new dependency to the plugin. The dependency will be validated during plugin initialization. AddDependency 向插件添加一个新的依赖项。 该依赖项将在插件初始化期间进行验证。

func (*BasePlugin) AddEventFilter

func (p *BasePlugin) AddEventFilter(filter EventFilter)

AddEventFilter adds a new event filter to the plugin. Events will be filtered according to the specified criteria. AddEventFilter 向插件添加一个新的事件过滤器。 事件将根据指定的条件进行过滤。

func (*BasePlugin) ApplyConfig

func (p *BasePlugin) ApplyConfig(conf any) error

ApplyConfig applies the validated configuration. This is called after configuration validation succeeds. ApplyConfig 应用经验证的配置。 此方法在配置验证成功后被调用。

func (*BasePlugin) CheckHealth

func (p *BasePlugin) CheckHealth() error

CheckHealth performs the actual health check operations. This is called during health status reporting. CheckHealth 执行实际的健康检查操作。 此方法在健康状态报告期间被调用。

func (*BasePlugin) CleanupTasks

func (p *BasePlugin) CleanupTasks() error

CleanupTasks performs cleanup during plugin shutdown. This method can be overridden by embedding structs to provide custom cleanup logic. CleanupTasks 在插件关闭期间执行清理操作。 嵌入结构体可以重写此方法以提供自定义清理逻辑。

func (*BasePlugin) Configure

func (p *BasePlugin) Configure(conf any) error

Configure updates the plugin's configuration with the provided settings. This method validates and applies new configuration values. Configure 使用提供的设置更新插件的配置。 此方法验证并应用新的配置值。

func (*BasePlugin) Description

func (p *BasePlugin) Description() string

Description returns a detailed description of the plugin's functionality. This helps users understand the plugin's purpose and capabilities. Description 返回插件功能的详细描述。 这有助于用户了解插件的用途和功能。

func (*BasePlugin) EmitEvent

func (p *BasePlugin) EmitEvent(event PluginEvent)

EmitEvent emits an event to the runtime event system. This method adds standard fields to the event before emission. EmitEvent 向运行时事件系统发出一个事件。 此方法在发出事件之前会向事件添加标准字段。

func (*BasePlugin) EmitEventInternal

func (p *BasePlugin) EmitEventInternal(event PluginEvent)

EmitEventInternal emits an event to the runtime event system. This method adds standard fields to the event before emission. EmitEventInternal 向运行时事件系统发出一个事件。 此方法在发出事件之前会向事件添加标准字段。

func (*BasePlugin) EventMatchesFilter

func (p *BasePlugin) EventMatchesFilter(event PluginEvent, filter EventFilter) bool

EventMatchesFilter checks if an event matches a specific filter. This implements the detailed filter matching logic. EventMatchesFilter 检查一个事件是否匹配特定的过滤器。 这实现了详细的过滤器匹配逻辑。

func (*BasePlugin) ExecuteUpgrade

func (p *BasePlugin) ExecuteUpgrade(targetVersion string) error

ExecuteUpgrade performs the plugin upgrade. This method checks if the plugin is in the upgrading state. ExecuteUpgrade 执行插件升级。 此方法检查插件是否处于升级状态。

func (*BasePlugin) GetCapabilities

func (p *BasePlugin) GetCapabilities() []UpgradeCapability

GetCapabilities returns the plugin's upgrade capabilities. GetCapabilities 返回插件的升级能力列表。

func (*BasePlugin) GetDependencies

func (p *BasePlugin) GetDependencies() []Dependency

GetDependencies returns the list of plugin dependencies. This includes both required and optional dependencies. GetDependencies 返回插件的依赖列表。 这包括必需和可选的依赖项。

func (*BasePlugin) GetHealth

func (p *BasePlugin) GetHealth() HealthReport

GetHealth performs a health check and returns a detailed health report. This method should be called periodically to monitor plugin health. GetHealth 执行健康检查并返回详细的健康报告。 应定期调用此方法以监控插件的健康状况。

func (*BasePlugin) HandleConfigEvent

func (p *BasePlugin) HandleConfigEvent(event PluginEvent)

HandleConfigEvent processes configuration-related events. This implements specific handling for configuration events. HandleConfigEvent 处理与配置相关的事件。 这实现了对配置事件的特定处理。

func (*BasePlugin) HandleDefaultEvent

func (p *BasePlugin) HandleDefaultEvent(event PluginEvent)

HandleDefaultEvent processes events that don't have specific handlers. This implements default event handling behavior. HandleDefaultEvent 处理没有特定处理程序的事件。 这实现了默认的事件处理行为。

func (*BasePlugin) HandleDependencyEvent

func (p *BasePlugin) HandleDependencyEvent(event PluginEvent)

HandleDependencyEvent processes dependency-related events. This implements specific handling for dependency events. HandleDependencyEvent 处理与依赖相关的事件。 这实现了对依赖事件的特定处理。

func (*BasePlugin) HandleEvent

func (p *BasePlugin) HandleEvent(event PluginEvent)

HandleEvent processes incoming plugin events. Events are filtered and handled according to configured filters. HandleEvent 处理传入的插件事件。 事件将根据配置的过滤器进行过滤和处理。

func (*BasePlugin) HandleHealthEvent

func (p *BasePlugin) HandleHealthEvent(event PluginEvent)

HandleHealthEvent processes health-related events. This implements specific handling for health events. HandleHealthEvent 处理与健康相关的事件。 这实现了对健康事件的特定处理。

func (*BasePlugin) ID

func (p *BasePlugin) ID() string

ID returns the unique identifier of the plugin. This ID must be unique across all plugins in the system. ID 返回插件的唯一标识符。 此 ID 在系统中的所有插件中必须是唯一的。

func (*BasePlugin) Initialize

func (p *BasePlugin) Initialize(plugin Plugin, rt Runtime) error

Initialize prepares the plugin for use by setting up its runtime environment. This method must be called before the plugin can be started. Initialize 通过设置运行时环境为插件使用做准备。 在启动插件之前必须调用此方法。

func (*BasePlugin) InitializeResources

func (p *BasePlugin) InitializeResources(rt Runtime) error

InitializeResources sets up the plugin's required resources. This method can be overridden by embedding structs to provide custom initialization. InitializeResources 设置插件所需的资源。 嵌入结构体可以重写此方法以提供自定义初始化逻辑。

func (*BasePlugin) Name

func (p *BasePlugin) Name() string

Name returns the human-readable name of the plugin. This name is used for display and logging purposes. Name 返回插件的易读名称。 此名称用于显示和日志记录目的。

func (*BasePlugin) PerformRollback

func (p *BasePlugin) PerformRollback(previousVersion string) error

PerformRollback handles the actual rollback process. This is an internal method called by RollbackUpgrade. PerformRollback 处理实际的回滚过程。 这是一个由 RollbackUpgrade 调用的内部方法。

func (*BasePlugin) PerformUpgrade

func (p *BasePlugin) PerformUpgrade(targetVersion string) error

PerformUpgrade handles the actual upgrade process. This is an internal method called by ExecuteUpgrade. PerformUpgrade 处理实际的升级过程。 这是一个由 ExecuteUpgrade 调用的内部方法。

func (*BasePlugin) PrepareUpgrade

func (p *BasePlugin) PrepareUpgrade(targetVersion string) error

PrepareUpgrade prepares the plugin for upgrade. This method checks if the plugin supports the upgrade capability. PrepareUpgrade 为插件升级做准备。 此方法检查插件是否支持升级能力。

func (*BasePlugin) RemoveEventFilter

func (p *BasePlugin) RemoveEventFilter(index int)

RemoveEventFilter removes an event filter from the plugin. This affects how future events will be processed. RemoveEventFilter 从插件中移除一个事件过滤器。 这会影响未来事件的处理方式。

func (*BasePlugin) Resume

func (p *BasePlugin) Resume() error

Resume resumes the plugin from suspended state. This method checks if the plugin is in the suspended state. Resume 从挂起状态恢复插件。 此方法检查插件是否处于挂起状态。

func (*BasePlugin) RollbackUpgrade

func (p *BasePlugin) RollbackUpgrade(previousVersion string) error

RollbackUpgrade rolls back the plugin upgrade. This method checks if the plugin is in the upgrading or failed state. RollbackUpgrade 回滚插件升级。 此方法检查插件是否处于升级或失败状态。

func (*BasePlugin) SetStatus

func (p *BasePlugin) SetStatus(status PluginStatus)

SetStatus sets the current operational status of the plugin. This method is thread-safe and should be used to update plugin status. SetStatus 设置插件当前的运行状态。 此方法是线程安全的,应使用它来更新插件状态。

func (*BasePlugin) ShouldEmitEvent

func (p *BasePlugin) ShouldEmitEvent(event PluginEvent) bool

ShouldEmitEvent checks if an event should be emitted based on filters. This implements the event filtering logic. ShouldEmitEvent 根据过滤器检查是否应该发出一个事件。 这实现了事件过滤逻辑。

func (*BasePlugin) ShouldHandleEvent

func (p *BasePlugin) ShouldHandleEvent(event PluginEvent) bool

ShouldHandleEvent checks if an event should be handled based on filters. This implements the event handling filter logic. ShouldHandleEvent 根据过滤器检查是否应该处理一个事件。 这实现了事件处理过滤逻辑。

func (*BasePlugin) Start

func (p *BasePlugin) Start(plugin Plugin) error

Start activates the plugin and begins its main operations. The plugin must be initialized before it can be started. Start 激活插件并开始其主要操作。 插件必须在初始化后才能启动。

func (*BasePlugin) StartupTasks

func (p *BasePlugin) StartupTasks() error

StartupTasks performs necessary tasks during plugin startup. This method can be overridden by embedding structs to provide custom startup logic. StartupTasks 在插件启动期间执行必要的任务。 嵌入结构体可以重写此方法以提供自定义启动逻辑。

func (*BasePlugin) Status

func (p *BasePlugin) Status(plugin Plugin) PluginStatus

Status returns the current operational status of the plugin. This method is thread-safe and can be called at any time. Status 返回插件当前的运行状态。 此方法是线程安全的,可以在任何时候调用。

func (*BasePlugin) Stop

func (p *BasePlugin) Stop(plugin Plugin) error

Stop gracefully terminates the plugin's operations. This method should release all resources and perform cleanup. Stop 优雅地终止插件的操作。 此方法应释放所有资源并执行清理操作。

func (*BasePlugin) SupportsCapability

func (p *BasePlugin) SupportsCapability(cap UpgradeCapability) bool

SupportsCapability checks if the plugin supports the specified upgrade capability. SupportsCapability 检查插件是否支持指定的升级能力。

func (*BasePlugin) Suspend

func (p *BasePlugin) Suspend() error

Suspend temporarily suspends the plugin. This method checks if the plugin is in the active state. Suspend 暂时挂起插件。 此方法检查插件是否处于活动状态。

func (*BasePlugin) ValidateConfig

func (p *BasePlugin) ValidateConfig(conf any) error

ValidateConfig validates the provided configuration. This is called before applying new configuration. ValidateConfig 验证提供的配置。 此方法在应用新配置之前被调用。

func (*BasePlugin) Version

func (p *BasePlugin) Version() string

Version returns the semantic version of the plugin. Version format should follow semver conventions (MAJOR.MINOR.PATCH). Version 返回插件的语义化版本。 版本格式应遵循语义化版本规范(MAJOR.MINOR.PATCH)。

func (*BasePlugin) Weight

func (p *BasePlugin) Weight() int

Weight 权重获取

type ConfigProvider

type ConfigProvider interface {
	// GetConfig returns the plugin configuration manager
	// Provides access to configuration values and updates
	// GetConfig 返回插件配置管理器。
	// 提供对配置值和更新的访问。
	GetConfig() config.Config
}

ConfigProvider provides access to plugin configuration Manages plugin configuration loading and access ConfigProvider 提供对插件配置的访问。 管理插件配置的加载和访问。

type Configurable

type Configurable interface {
	// Configure applies and validates the given configuration
	// Updates plugin configuration during runtime
	// Configure 应用并验证给定的配置。
	// 在运行时更新插件配置。
	Configure(conf any) error
}

Configurable defines methods for plugin configuration management Manages plugin configuration updates and validation Configurable 定义了插件配置管理的方法。 管理插件配置的更新和验证。

type Dependency

type Dependency struct {
	ID       string            // Unique identifier of the required plugin // 所需插件的唯一标识符
	Required bool              // Whether this dependency is mandatory // 此依赖项是否为必需项
	Checker  DependencyChecker // Validates dependency requirements // 验证依赖项要求
	Metadata map[string]any    // Additional dependency information // 额外的依赖项信息
}

Dependency describes a dependency relationship between plugins Defines requirements and relationships between plugins Dependency 描述了插件之间的依赖关系。 定义了插件之间的需求和关系。

type DependencyAware

type DependencyAware interface {
	// GetDependencies returns the list of plugin dependencies
	// Lists all required and optional dependencies
	// GetDependencies 返回插件依赖项列表。
	// 列出所有必需和可选的依赖项。
	GetDependencies() []Dependency
}

DependencyAware defines methods for plugin dependency management Manages plugin dependencies and their relationships DependencyAware 定义了插件依赖管理的方法。 管理插件依赖项及其关系。

type DependencyChecker

type DependencyChecker interface {
	// Check validates if the dependency condition is met
	// Returns true if the dependency is satisfied
	// Check 验证依赖项条件是否满足。
	// 如果依赖项满足,则返回 true。
	Check(plugin Plugin) bool

	// Description returns a human-readable description of the condition
	// Explains what the dependency checker validates
	// Description 返回条件的易读描述。
	// 解释依赖项检查器验证的内容。
	Description() string
}

DependencyChecker defines the interface for dependency validation Validates plugin dependencies and their conditions DependencyChecker 定义了依赖项验证的接口。 验证插件依赖项及其条件。

type EventEmitter

type EventEmitter interface {
	// EmitEvent broadcasts a plugin event to all registered listeners.
	// Event will be processed according to its priority and any active filters.
	// EmitEvent 向所有注册的监听器广播一个插件事件。
	// 事件将根据其优先级和任何活动的过滤器进行处理。
	EmitEvent(event PluginEvent)

	// AddListener registers a new event listener with optional filters.
	// Listener will only receive events that match its filter criteria.
	// AddListener 使用可选的过滤器注册一个新的事件监听器。
	// 监听器将仅接收符合其过滤条件的事件。
	AddListener(listener EventListener, filter *EventFilter)

	// RemoveListener unregisters an event listener.
	// After removal, the listener will no longer receive any events.
	// RemoveListener 注销一个事件监听器。
	// 删除后,该监听器将不再接收任何事件。
	RemoveListener(listener EventListener)

	// GetEventHistory retrieves historical events based on filter criteria.
	// Returns events that match the specified filter parameters.
	// GetEventHistory 根据过滤条件检索历史事件。
	// 返回符合指定过滤参数的事件。
	GetEventHistory(filter EventFilter) []PluginEvent
}

EventEmitter defines the interface for the plugin event system. EventEmitter 定义了插件事件系统的接口。

type EventFilter

type EventFilter struct {
	// Types specifies which event types to include
	// Types 指定要包含的事件类型。
	Types []EventType

	// Priorities specifies which priority levels to include
	// Priorities 指定要包含的优先级级别。
	Priorities []int

	// PluginIDs specifies which plugins to monitor
	// PluginIDs 指定要监控的插件。
	PluginIDs []string

	// Categories specifies which event categories to include
	// Categories 指定要包含的事件类别。
	Categories []string

	// FromTime specifies the start time for event filtering
	// FromTime 指定事件过滤的开始时间。
	FromTime int64

	// ToTime specifies the end time for event filtering
	// ToTime 指定事件过滤的结束时间。
	ToTime int64
}

EventFilter defines criteria for filtering plugin events. It allows selective processing of events based on various attributes. EventFilter 定义了过滤插件事件的标准。 它允许根据各种属性选择性地处理事件。

type EventHandler

type EventHandler interface {
	// HandleEvent processes plugin lifecycle events
	// Handles various plugin system events
	// HandleEvent 处理插件生命周期事件。
	// 处理各种插件系统事件。
	HandleEvent(event PluginEvent)
}

EventHandler defines methods for plugin event handling Processes plugin-related events and notifications EventHandler 定义了插件事件处理的方法。 处理与插件相关的事件和通知。

type EventListener

type EventListener interface {
	// HandleEvent processes plugin lifecycle events.
	// Implementation should handle the event according to its type and priority.
	// HandleEvent 处理插件生命周期事件。
	// 实现应根据事件的类型和优先级处理事件。
	HandleEvent(event PluginEvent)

	// GetListenerID returns a unique identifier for the listener.
	// Used for listener management and filtering.
	// GetListenerID 返回监听器的唯一标识符。
	// 用于监听器管理和过滤。
	GetListenerID() string
}

EventListener defines the interface for handling plugin events. EventListener 定义了处理插件事件的接口。

type EventProcessor

type EventProcessor interface {
	// ProcessEvent processes an event through all registered filters.
	// Returns true if the event should be propagated, false if it should be filtered.
	// ProcessEvent 通过所有注册的过滤器处理事件。
	// 如果事件应该被传播则返回 true,如果应该被过滤则返回 false。
	ProcessEvent(event PluginEvent) bool

	// AddFilter adds a new event filter to the processor.
	// Filter will be applied to all subsequent events.
	// AddFilter 向处理器添加一个新的事件过滤器。
	// 该过滤器将应用于所有后续事件。
	AddFilter(filter EventFilter)

	// RemoveFilter removes an event filter by its ID.
	// Events will no longer be filtered by the removed filter.
	// RemoveFilter 根据过滤器 ID 删除一个事件过滤器。
	// 事件将不再被删除的过滤器过滤。
	RemoveFilter(filterID string)
}

EventProcessor provides event processing and filtering capabilities. EventProcessor 提供事件处理和过滤功能。

type EventType

type EventType string

EventType represents the type of event that occurred in the plugin system. EventType 表示插件系统中发生的事件类型。

type HealthCheck

type HealthCheck interface {
	// GetHealth returns the current health status of the plugin
	// Provides detailed health information
	// GetHealth 返回插件的当前健康状态。
	// 提供详细的健康信息。
	GetHealth() HealthReport
}

HealthCheck defines methods for plugin health monitoring Provides health status and monitoring capabilities HealthCheck 定义了插件健康监控的方法。 提供健康状态和监控功能。

type HealthReport

type HealthReport struct {
	Status    string         // Current health status (healthy, degraded, unhealthy) // 当前健康状态(健康、降级、不健康)
	Details   map[string]any // Detailed health metrics and information // 详细的健康指标和信息
	Timestamp int64          // Time of the health check (Unix timestamp) // 健康检查的时间(Unix 时间戳)
	Message   string         // Optional descriptive message // 可选的描述性消息
}

HealthReport represents the detailed health status of a plugin Provides comprehensive health information for monitoring HealthReport 表示插件的详细健康状态。 提供全面的健康信息用于监控。

type IDFormat

type IDFormat struct {
	Organization string // e.g., "go-lynx" // 例如,"go-lynx"
	Type         string // e.g., "plugin" // 例如,"plugin"
	Name         string // e.g., "http" // 例如,"http"
	Version      string // e.g., "v1" or "v1.0.0" // 例如,"v1" 或 "v1.0.0"
}

IDFormat represents the components of a plugin ID IDFormat 表示插件 ID 的各个组成部分

func ParsePluginID

func ParsePluginID(id string) (*IDFormat, error)

ParsePluginID parses a plugin ID string into its components ParsePluginID 将插件 ID 字符串解析为其各个组成部分

type Lifecycle

type Lifecycle interface {
	// Initialize prepares the plugin for use
	// Sets up resources, connections, and internal state
	// Returns error if initialization fails
	// Initialize 为插件的使用做准备。
	// 设置资源、连接和内部状态。
	// 如果初始化失败,则返回错误。
	Initialize(plugin Plugin, rt Runtime) error

	// Start begins the plugin's main functionality
	// Should only be called after successful initialization
	// Returns error if startup fails
	// Start 启动插件的主要功能。
	// 仅应在初始化成功后调用。
	// 如果启动失败,则返回错误。
	Start(plugin Plugin) error

	// Stop gracefully terminates the plugin's functionality
	// Releases resources and closes connections
	// Returns error if shutdown fails
	// Stop 优雅地终止插件的功能。
	// 释放资源并关闭连接。
	// 如果关闭失败,则返回错误。
	Stop(plugin Plugin) error

	// Status returns the current status of the plugin
	// Provides real-time state information
	// Status 返回插件的当前状态。
	// 提供实时状态信息。
	Status(plugin Plugin) PluginStatus
}

Lifecycle defines the basic lifecycle methods for a plugin Handles initialization, operation, and termination of the plugin Lifecycle 定义了插件的基本生命周期方法。 处理插件的初始化、运行和终止操作。

type LifecycleSteps

type LifecycleSteps interface {
	InitializeResources(rt Runtime) error
	StartupTasks() error
	CleanupTasks() error
	CheckHealth() error
}

type LogProvider

type LogProvider interface {
	// GetLogger returns the plugin logger instance
	// Provides structured logging capabilities
	// GetLogger 返回插件日志记录器实例。
	// 提供结构化的日志记录功能。
	GetLogger() log.Logger
}

LogProvider provides access to logging functionality Manages plugin logging capabilities LogProvider 提供对日志记录功能的访问。 管理插件的日志记录能力。

type Metadata

type Metadata interface {
	// ID returns the unique identifier of the plugin
	// This ID must be unique across all plugins in the system
	// ID 返回插件的唯一标识符。
	// 该 ID 在系统中的所有插件中必须是唯一的。
	ID() string

	// Name returns the display name of the plugin
	// This is a human-readable name used for display purposes
	// Name 返回插件的显示名称。
	// 这是一个用于显示目的的易读名称。
	Name() string

	// Description returns a detailed description of the plugin
	// Should provide information about the plugin's purpose and functionality
	// Description 返回插件的详细描述。
	// 应提供有关插件用途和功能的信息。
	Description() string

	// Version returns the semantic version of the plugin
	// Should follow semver format (MAJOR.MINOR.PATCH)
	// Version 返回插件的语义化版本。
	// 应遵循语义化版本格式(MAJOR.MINOR.PATCH)。
	Version() string

	// Weight 权重获取
	Weight() int
}

Metadata defines methods for retrieving plugin metadata This interface provides essential information about the plugin Metadata 定义了用于获取插件元数据的方法。 此接口提供了有关插件的基本信息。

type Plugin

type Plugin interface {
	Metadata
	Lifecycle
	LifecycleSteps
	DependencyAware
}

Plugin is the minimal interface that all plugins must implement It combines basic metadata and lifecycle management capabilities Plugin 是所有插件都必须实现的最小接口。 它整合了基本的元数据和生命周期管理功能。

type PluginError

type PluginError struct {
	// PluginID identifies the plugin where the error occurred
	// PluginID 标识出错的插件。
	PluginID string

	// Operation describes the action that was being performed when the error occurred
	// Operation 描述出错时正在执行的操作。
	Operation string

	// Message provides a detailed description of the error
	// Message 提供错误的详细描述。
	Message string

	// Err is the underlying error that caused this PluginError
	// Err 是导致此 PluginError 的底层错误。
	Err error
}

PluginError represents a detailed error that occurred during plugin operations PluginError 表示插件操作过程中发生的详细错误。

func NewPluginError

func NewPluginError(pluginID, operation, message string, err error) *PluginError

NewPluginError creates a new PluginError with the given details Provides a convenient way to create structured plugin errors NewPluginError 使用给定的详细信息创建一个新的 PluginError。 提供了一种方便的方式来创建结构化的插件错误。

func (*PluginError) Error

func (e *PluginError) Error() string

Error implements the error interface for PluginError Returns a formatted error message including plugin ID, operation, and details Error 为 PluginError 实现 error 接口。 返回包含插件 ID、操作和详细信息的格式化错误消息。

func (*PluginError) Unwrap

func (e *PluginError) Unwrap() error

Unwrap implements the errors unwrap interface Returns the underlying error for error chain handling Unwrap 实现 errors 解包接口。 返回底层错误以进行错误链处理。

type PluginEvent

type PluginEvent struct {
	// Type indicates the specific kind of event that occurred
	// Type 表示发生的具体事件类型。
	Type EventType

	// Priority indicates the importance level of the event
	// Priority 表示事件的重要程度。
	Priority int

	// PluginID identifies the plugin that generated the event
	// PluginID 标识生成该事件的插件。
	PluginID string

	// Source identifies where in the plugin the event originated
	// Source 标识事件在插件中的起源位置。
	Source string

	// Category groups related events for easier filtering
	// Category 对相关事件进行分组,以便于过滤。
	Category string

	// Status represents the plugin's state when event occurred
	// Status 表示事件发生时插件的状态。
	Status PluginStatus

	// Error contains any error information if applicable
	// Error 包含适用的错误信息。
	Error error

	// Metadata contains additional event-specific information
	// Metadata 包含事件特定的额外信息。
	Metadata map[string]any

	// Timestamp records when the event occurred
	// Timestamp 记录事件发生的时间。
	Timestamp int64
}

PluginEvent represents a lifecycle event in the plugin system. It contains detailed information about the event, including its type, priority, source, and any associated metadata. PluginEvent 表示插件系统中的一个生命周期事件。 它包含有关事件的详细信息,包括事件类型、优先级、来源以及任何关联的元数据。

type PluginStatus

type PluginStatus int

PluginStatus represents the current operational status of a plugin in the system. It tracks the plugin's lifecycle state from initialization through termination. PluginStatus 表示系统中插件的当前运行状态。 它跟踪插件从初始化到终止的整个生命周期状态。

const (
	// StatusInactive indicates that the plugin is loaded but not yet initialized
	// This is the initial state of a plugin when it is first loaded into the system
	// StatusInactive 表示插件已加载但尚未初始化。
	// 这是插件首次加载到系统中的初始状态。
	StatusInactive PluginStatus = iota

	// StatusInitializing indicates that the plugin is currently performing initialization
	// During this state, the plugin is setting up resources, establishing connections,
	// and preparing for normal operation
	// StatusInitializing 表示插件当前正在进行初始化。
	// 在此状态下,插件会设置资源、建立连接并为正常运行做准备。
	StatusInitializing

	// StatusActive indicates that the plugin is fully operational and running normally
	// In this state, the plugin is processing requests and performing its intended functions
	// StatusActive 表示插件已完全投入运行且正常工作。
	// 在此状态下,插件会处理请求并执行其预定功能。
	StatusActive

	// StatusSuspended indicates that the plugin is temporarily paused
	// The plugin retains its resources but is not processing new requests
	// Can be resumed to StatusActive without full reinitialization
	// StatusSuspended 表示插件已被暂时暂停。
	// 插件会保留其资源,但不会处理新请求。
	// 可以在不进行完全重新初始化的情况下恢复到 StatusActive 状态。
	StatusSuspended

	// StatusStopping indicates that the plugin is in the process of shutting down
	// During this state, the plugin is cleaning up resources and finishing pending operations
	// StatusStopping 表示插件正在关闭过程中。
	// 在此状态下,插件会清理资源并完成未完成的操作。
	StatusStopping

	// StatusTerminated indicates that the plugin has been gracefully shut down
	// All resources have been released and connections closed
	// Requires full reinitialization to become active again
	// StatusTerminated 表示插件已正常关闭。
	// 所有资源已释放,连接已关闭。
	// 若要再次激活,需要进行完全重新初始化。
	StatusTerminated

	// StatusFailed indicates that the plugin has encountered a fatal error
	// The plugin is non-operational and may require manual intervention
	// Should transition to StatusTerminated or attempt recovery
	// StatusFailed 表示插件遇到了致命错误。
	// 插件无法正常工作,可能需要手动干预。
	// 应转换到 StatusTerminated 状态或尝试恢复。
	StatusFailed

	// StatusUpgrading indicates that the plugin is currently being upgraded
	// During this state, the plugin may be partially operational
	// Should transition to StatusActive or StatusFailed
	// StatusUpgrading 表示插件当前正在升级。
	// 在此状态下,插件可能部分可用。
	// 升级后应转换到 StatusActive 或 StatusFailed 状态。
	StatusUpgrading

	// StatusRollback indicates that the plugin is rolling back from a failed upgrade
	// Attempting to restore the previous working state
	// Should transition to StatusActive or StatusFailed
	// StatusRollback 表示插件正在从失败的升级中回滚。
	// 尝试恢复到之前的工作状态。
	// 回滚后应转换到 StatusActive 或 StatusFailed 状态。
	StatusRollback
)

type ResourceManager

type ResourceManager interface {
	// GetResource retrieves a shared plugin resource by name
	// Returns the resource and any error encountered
	// GetResource 根据名称获取插件共享资源。
	// 返回资源和可能遇到的错误。
	GetResource(name string) (any, error)

	// RegisterResource registers a resource to be shared with other plugins
	// Returns error if registration fails
	// RegisterResource 注册一个资源,以便与其他插件共享。
	// 如果注册失败,则返回错误。
	RegisterResource(name string, resource any) error
}

ResourceManager provides access to shared plugin resources Manages resource allocation, sharing, and lifecycle ResourceManager 提供对插件共享资源的访问。 管理资源分配、共享和生命周期。

type Runtime

Runtime combines all runtime capabilities for plugins Provides a complete runtime environment for plugin operation Runtime 整合了插件的所有运行时功能。 为插件运行提供完整的运行时环境。

type Suspendable

type Suspendable interface {
	// Suspend temporarily suspends plugin operations
	// Pauses plugin activity while maintaining state
	// Suspend 临时暂停插件操作。
	// 在保持状态的同时暂停插件活动。
	Suspend() error

	// Resume restores plugin operations from a suspended state
	// Resumes normal operation without reinitialization
	// Resume 从暂停状态恢复插件操作。
	// 无需重新初始化即可恢复正常运行。
	Resume() error
}

Suspendable defines methods for temporary plugin suspension Manages temporary plugin deactivation and reactivation Suspendable 定义了插件临时暂停的方法。 管理插件的临时停用和重新激活。

type Upgradable

type Upgradable interface {
	// GetCapabilities returns the supported upgrade capabilities
	// Lists the ways this plugin can be upgraded
	// GetCapabilities 返回支持的升级能力。
	// 列出此插件可进行升级的方式。
	GetCapabilities() []UpgradeCapability

	// PrepareUpgrade prepares for version upgrade
	// Validates and prepares for the upgrade process
	// PrepareUpgrade 为版本升级做准备。
	// 验证并为升级过程做准备。
	PrepareUpgrade(targetVersion string) error

	// ExecuteUpgrade performs the actual version upgrade
	// Applies the upgrade and verifies success
	// ExecuteUpgrade 执行实际的版本升级。
	// 应用升级并验证是否成功。
	ExecuteUpgrade(targetVersion string) error

	// RollbackUpgrade reverts to the previous version
	// Restores the plugin to its previous state
	// RollbackUpgrade 回滚到上一个版本。
	// 将插件恢复到之前的状态。
	RollbackUpgrade(previousVersion string) error
}

Upgradable defines methods for plugin upgrade operations Manages plugin version upgrades and updates Upgradable 定义了插件升级操作的方法。 管理插件版本升级和更新。

type UpgradeCapability

type UpgradeCapability int

UpgradeCapability defines the various ways a plugin can be upgraded during runtime UpgradeCapability 定义了插件在运行时可进行升级的各种方式。

const (
	// UpgradeNone indicates the plugin does not support any runtime upgrades
	// Must be stopped and restarted to apply any changes
	// UpgradeNone 表示插件不支持任何运行时升级。
	// 若要应用任何更改,必须停止并重新启动插件。
	UpgradeNone UpgradeCapability = iota

	// UpgradeConfig indicates the plugin can update its configuration without restart
	// Supports runtime configuration changes but not code updates
	// UpgradeConfig 表示插件可以在不重启的情况下更新其配置。
	// 支持运行时配置更改,但不支持代码更新。
	UpgradeConfig

	// UpgradeVersion indicates the plugin can perform version upgrades without restart
	// Supports both configuration and code updates during runtime
	// UpgradeVersion 表示插件可以在不重启的情况下进行版本升级。
	// 支持在运行时同时更新配置和代码。
	UpgradeVersion

	// UpgradeReplace indicates the plugin supports complete replacement during runtime
	// Can be entirely replaced with a new instance while maintaining service
	// UpgradeReplace 表示插件支持在运行时进行完全替换。
	// 可以在保持服务运行的同时,用新实例完全替换当前插件。
	UpgradeReplace
)

Directories

Path Synopsis
db
mysql Module
pgsql Module
mq
kafka Module
nosql
redis Module
polaris module
seata module
service
grpc Module
http Module
tracer module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL