Documentation
ยถ
Overview ยถ
Package lynx provides the core application framework for building microservices.
This file (app.go) contains the LynxApp structure and main API entry points.
Package lynx provides the core application framework for building microservices.
This file (certificate.go) contains TLS certificate management:
- CertificateProvider: Interface for accessing TLS certificates
- Certificate and private key retrieval
- Root CA certificate for trust chain verification
Package lynx provides the core application framework for building microservices.
This file (controlplane.go) contains the control plane interfaces and implementation:
- ControlPlane: Main interface for service management
- RateLimiter: HTTP and gRPC rate limiting
- ServiceRegistry: Service registration and discovery
- RouteManager: Service routing and node filtering
- ConfigManager: Configuration source management
- DefaultControlPlane: Basic implementation for local development
Package lynx provides the core application framework for building microservices.
Lynx is a plug-and-play Go microservices framework built on top of Kratos, providing a unified runtime environment for plugin-based application development.
Architecture ยถ
The framework is organized around the following core concepts:
- LynxApp: The main application instance managing lifecycle and configuration
- Plugin Manager: Handles plugin registration, dependency resolution, and lifecycle
- Runtime: Provides resource sharing, event handling, and configuration access
- Control Plane: Manages service discovery, rate limiting, and routing
File Organization ยถ
The root package contains the following files:
- app.go: LynxApp core structure, initialization, and main API
- manager.go: Plugin manager interfaces and implementation
- lifecycle.go: Plugin lifecycle operations (init/start/stop)
- ops.go: Plugin loading and unloading operations
- topology.go: Plugin dependency resolution and ordering
- runtime.go: Runtime plugin providing resource and event management
- controlplane.go: Control plane interfaces for service management
- certificate.go: TLS certificate provider interface
- prepare.go: Plugin preparation and bootstrapping from configuration
- recovery.go: Error recovery and resilience mechanisms
Quick Start ยถ
Basic usage of the Lynx framework:
package main
import (
"github.com/go-kratos/kratos/v2/config"
"github.com/go-kratos/kratos/v2/config/file"
"github.com/go-lynx/lynx"
"github.com/go-lynx/lynx/boot"
)
func main() {
// Load configuration
cfg := config.New(config.WithSource(file.NewSource("config.yaml")))
cfg.Load()
// Create application with plugins
app, err := lynx.NewApp(cfg)
if err != nil {
panic(err)
}
defer app.Close()
// Load and start plugins
if err := app.GetPluginManager().LoadPlugins(cfg); err != nil {
panic(err)
}
// Run application using boot package
boot.Run(app)
}
Plugin Development ยถ
To create a custom plugin, implement the plugins.Plugin interface:
type MyPlugin struct {
*plugins.BasePlugin
}
func (p *MyPlugin) Name() string { return "my-plugin" }
func (p *MyPlugin) ID() string { return "my-plugin-v1" }
func (p *MyPlugin) Initialize(plugin plugins.Plugin, rt plugins.Runtime) error {
// Initialization logic
return nil
}
func (p *MyPlugin) Start(plugin plugins.Plugin) error {
// Startup logic
return nil
}
func (p *MyPlugin) Stop(plugin plugins.Plugin) error {
// Shutdown logic
return nil
}
Configuration ยถ
The framework uses YAML configuration files. See conf/boot-example.yml for a complete configuration reference.
For More Information ยถ
Visit the official documentation at https://go-lynx.cn/docs
Package lynx provides the core application framework for building microservices.
This file (lifecycle.go) contains plugin lifecycle operations including:
- Plugin initialization with timeout and error recovery
- Plugin startup with parallel execution and rollback
- Plugin shutdown with graceful termination
- Context-aware lifecycle support for cancellation
Package lynx provides the core application framework for building microservices.
This file (manager.go) contains the plugin manager interfaces and implementation. The plugin manager handles plugin registration, lookup, and lifecycle coordination.
Package lynx provides the core application framework for building microservices.
This file (ops.go) contains plugin manager operations including:
- LoadPlugins: Load and start all configured plugins
- UnloadPlugins: Gracefully stop and unload all plugins
- LoadPluginsByName: Load specific plugins by name
- UnloadPluginsByName: Unload specific plugins by name
- StopPlugin: Stop a single plugin
- Resource management and monitoring utilities
Package lynx provides the core application framework for building microservices.
This file (prepare.go) contains plugin preparation and bootstrapping:
- PreparePlug: Bootstrap plugin loading from configuration
- Plugin factory integration for automatic plugin creation
- Configuration-driven plugin registration
Package lynx provides the core application framework for building microservices.
This file (recovery.go) contains error recovery and resilience mechanisms:
- CircuitBreaker: Prevents cascading failures
- ErrorRecoveryManager: Manages error detection and recovery
- Health monitoring and automatic recovery strategies
- Panic recovery with detailed diagnostics
Package lynx provides the core application framework for building microservices.
This file (runtime.go) contains the runtime plugin implementation:
- TypedRuntimePlugin: Core runtime for resource and event management
- Resource registration and retrieval (shared and private)
- Event emission and listener management
- Configuration access and updates
- Plugin context management
Package lynx provides the core application framework for building microservices.
This file (topology.go) contains plugin dependency resolution utilities:
- TopologicalSort: Sort plugins based on dependencies
- Dependency graph construction and validation
- Level calculation for parallel plugin loading
Index ยถ
- func GetHost() string
- func GetName() string
- func GetServiceDiscovery() (registry.Discovery, error)
- func GetServiceRegistry() (registry.Registrar, error)
- func GetTypedPlugin[T plugins.Plugin](name string) (T, error)
- func GetTypedPluginFromManager[T plugins.Plugin](m TypedPluginManager, name string) (T, error)
- func GetTypedResource[T any](r *TypedRuntimePlugin, name string) (T, error)
- func GetVersion() string
- func ListPluginNames(m TypedPluginManager) []string
- func MustGetTypedPluginFromManager[T plugins.Plugin](m TypedPluginManager, name string) T
- func Plugins(m TypedPluginManager) []plugins.Plugin
- func RegisterTypedResource[T any](r *TypedRuntimePlugin, name string, resource T) error
- type CertificateProvider
- type CircuitBreaker
- type CircuitState
- type ConfigManager
- type ControlPlane
- type DefaultControlPlane
- func (c *DefaultControlPlane) GRPCRateLimit() middleware.Middleware
- func (c *DefaultControlPlane) GetConfig(fileName string, group string) (config.Source, error)
- func (c *DefaultControlPlane) GetNamespace() string
- func (c *DefaultControlPlane) HTTPRateLimit() middleware.Middleware
- func (c *DefaultControlPlane) NewNodeRouter(serviceName string) selector.NodeFilter
- func (c *DefaultControlPlane) NewServiceDiscovery() registry.Discovery
- func (c *DefaultControlPlane) NewServiceRegistry() registry.Registrar
- type DefaultPluginManager
- func (m *DefaultPluginManager[T]) ClearUnloadFailures()
- func (m *DefaultPluginManager[T]) GetPlugin(name string) plugins.Plugin
- func (m *DefaultPluginManager[T]) GetResourceStats() map[string]any
- func (m *DefaultPluginManager[T]) GetRuntime() plugins.Runtime
- func (m *DefaultPluginManager[T]) GetUnloadFailures() []UnloadFailureRecord
- func (m *DefaultPluginManager[T]) ListResources() []*plugins.ResourceInfo
- func (m *DefaultPluginManager[T]) LoadPlugins(conf config.Config) error
- func (m *DefaultPluginManager[T]) LoadPluginsByName(conf config.Config, pluginNames []string) error
- func (m *DefaultPluginManager[T]) PreparePlug(config config.Config) ([]plugins.Plugin, error)
- func (m *DefaultPluginManager[T]) SetConfig(conf config.Config)
- func (m *DefaultPluginManager[T]) StopPlugin(pluginName string) error
- func (m *DefaultPluginManager[T]) TopologicalSort(plugs []plugins.Plugin) ([]PluginWithLevel, error)
- func (m *DefaultPluginManager[T]) UnloadOrder(plugs []plugins.Plugin) []plugins.Plugin
- func (m *DefaultPluginManager[T]) UnloadPlugins()
- func (m *DefaultPluginManager[T]) UnloadPluginsByName(names []string)
- type DefaultRecoveryStrategy
- type ErrorCategory
- type ErrorRecord
- type ErrorRecoveryManager
- func (erm *ErrorRecoveryManager) ClearHistory()
- func (erm *ErrorRecoveryManager) GetErrorHistory() []ErrorRecord
- func (erm *ErrorRecoveryManager) GetErrorStats() map[string]interface{}
- func (erm *ErrorRecoveryManager) GetHealthReport() map[string]interface{}
- func (erm *ErrorRecoveryManager) GetRecoveryHistory() []RecoveryRecord
- func (erm *ErrorRecoveryManager) IsHealthy() bool
- func (erm *ErrorRecoveryManager) RecordError(errorType string, category ErrorCategory, message, component string, ...)
- func (erm *ErrorRecoveryManager) RegisterRecoveryStrategy(errorType string, strategy RecoveryStrategy)
- func (erm *ErrorRecoveryManager) Stop()
- type ErrorSeverity
- type LynxApp
- func (a *LynxApp) Certificate() CertificateProvider
- func (a *LynxApp) ClearUnloadFailures()
- func (a *LynxApp) Close() error
- func (a *LynxApp) GetControlPlane() ControlPlane
- func (a *LynxApp) GetControlPlaneConfigSources() ([]config.Source, error)
- func (a *LynxApp) GetGlobalConfig() config.Config
- func (a *LynxApp) GetPluginManager() TypedPluginManager
- func (a *LynxApp) GetResourceStats() map[string]any
- func (a *LynxApp) GetTypedPluginManager() TypedPluginManager
- func (a *LynxApp) GetUnloadFailures() []UnloadFailureRecord
- func (a *LynxApp) InitControlPlaneConfig() (config.Config, error)
- func (a *LynxApp) SetCertificateProvider(provider CertificateProvider)
- func (a *LynxApp) SetControlPlane(plane ControlPlane) error
- func (a *LynxApp) SetGlobalConfig(cfg config.Config) error
- func (a *LynxApp) Shutdown() error
- type MultiConfigControlPlane
- type PluginManager
- type PluginWithLevel
- type RateLimiter
- type RecoveryRecord
- type RecoveryStrategy
- type RouteManager
- type RuntimePlugin
- type ServiceRegistry
- type SystemCore
- type TypedPluginManager
- type TypedRuntimePlugin
- func (r *TypedRuntimePlugin) AddListener(listener plugins.EventListener, filter *plugins.EventFilter)
- func (r *TypedRuntimePlugin) AddPluginListener(pluginName string, listener plugins.EventListener, filter *plugins.EventFilter)
- func (r *TypedRuntimePlugin) CleanupResources(pluginID string) error
- func (r *TypedRuntimePlugin) Close()
- func (r *TypedRuntimePlugin) EmitEvent(event plugins.PluginEvent)
- func (r *TypedRuntimePlugin) EmitPluginEvent(pluginName string, eventType string, data map[string]any)
- func (r *TypedRuntimePlugin) GetConfig() config.Config
- func (r *TypedRuntimePlugin) GetCurrentPluginContext() string
- func (r *TypedRuntimePlugin) GetEventHistory(filter plugins.EventFilter) []plugins.PluginEvent
- func (r *TypedRuntimePlugin) GetEventStats() map[string]any
- func (r *TypedRuntimePlugin) GetLogger() log.Logger
- func (r *TypedRuntimePlugin) GetPluginEventHistory(pluginName string, filter plugins.EventFilter) []plugins.PluginEvent
- func (r *TypedRuntimePlugin) GetPrivateResource(name string) (any, error)
- func (r *TypedRuntimePlugin) GetResource(name string) (any, error)
- func (r *TypedRuntimePlugin) GetResourceInfo(name string) (*plugins.ResourceInfo, error)
- func (r *TypedRuntimePlugin) GetResourceStats() map[string]any
- func (r *TypedRuntimePlugin) GetSharedResource(name string) (any, error)
- func (r *TypedRuntimePlugin) ListResources() []*plugins.ResourceInfo
- func (r *TypedRuntimePlugin) RegisterPrivateResource(name string, resource any) error
- func (r *TypedRuntimePlugin) RegisterResource(name string, resource any) error
- func (r *TypedRuntimePlugin) RegisterSharedResource(name string, resource any) error
- func (r *TypedRuntimePlugin) RemoveListener(listener plugins.EventListener)
- func (r *TypedRuntimePlugin) SetConfig(conf config.Config)
- func (r *TypedRuntimePlugin) SetEventDispatchMode(mode string) error
- func (r *TypedRuntimePlugin) SetEventTimeout(timeout time.Duration)
- func (r *TypedRuntimePlugin) SetEventWorkerPoolSize(size int)
- func (r *TypedRuntimePlugin) WithPluginContext(pluginName string) plugins.Runtime
- type UnloadFailureRecord
Constants ยถ
This section is empty.
Variables ยถ
This section is empty.
Functions ยถ
func GetHost ยถ
func GetHost() string
GetHost retrieves the hostname of the current application instance. Returns an empty string if the application is not initialized.
func GetName ยถ
func GetName() string
GetName retrieves the application name. Returns an empty string if the application is not initialized.
func GetServiceDiscovery ยถ
GetServiceDiscovery returns a new service discovery instance
func GetServiceRegistry ยถ
GetServiceRegistry returns a new service registry instance
func GetTypedPlugin ยถ
GetTypedPlugin globally retrieves a type-safe plugin instance
func GetTypedPluginFromManager ยถ
func GetTypedPluginFromManager[T plugins.Plugin](m TypedPluginManager, name string) (T, error)
GetTypedPluginFromManager gets a typed plugin from any TypedPluginManager.
func GetTypedResource ยถ
func GetTypedResource[T any](r *TypedRuntimePlugin, name string) (T, error)
GetTypedResource retrieves a type-safe resource (standalone helper)
func GetVersion ยถ
func GetVersion() string
GetVersion retrieves the application version. Returns an empty string if the application is not initialized.
func ListPluginNames ยถ
func ListPluginNames(m TypedPluginManager) []string
ListPluginNames Public helpers for any TypedPluginManager.
func MustGetTypedPluginFromManager ยถ
func MustGetTypedPluginFromManager[T plugins.Plugin](m TypedPluginManager, name string) T
MustGetTypedPluginFromManager gets typed plugin or panics.
func Plugins ยถ
func Plugins(m TypedPluginManager) []plugins.Plugin
func RegisterTypedResource ยถ
func RegisterTypedResource[T any](r *TypedRuntimePlugin, name string, resource T) error
RegisterTypedResource registers a type-safe resource (standalone helper)
Types ยถ
type CertificateProvider ยถ
type CertificateProvider interface {
// GetCertificate returns the TLS/SSL certificate as a byte slice.
// The certificate should be in PEM format.
GetCertificate() []byte
// GetPrivateKey returns the private key associated with the certificate as a byte slice.
// The private key should be in PEM format.
GetPrivateKey() []byte
// GetRootCACertificate returns the root CA certificate as a byte slice.
// The root CA certificate should be in PEM format.
// This certificate is used to verify the trust chain.
GetRootCACertificate() []byte
}
CertificateProvider defines an interface for managing TLS/SSL certificates. It provides methods to access the certificate, private key, and root Certificate Authority (CA) certificate required for secure communication.
type CircuitBreaker ยถ
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker provides error handling and recovery
func (*CircuitBreaker) CanExecute ยถ
func (cb *CircuitBreaker) CanExecute() bool
CanExecute checks if the circuit breaker allows execution
func (*CircuitBreaker) GetState ยถ
func (cb *CircuitBreaker) GetState() CircuitState
GetState returns the current circuit breaker state
func (*CircuitBreaker) RecordResult ยถ
func (cb *CircuitBreaker) RecordResult(err error)
RecordResult records the result of an operation
type CircuitState ยถ
type CircuitState int
CircuitState represents the state of circuit breaker
const ( CircuitStateClosed CircuitState = iota CircuitStateOpen CircuitStateHalfOpen )
type ConfigManager ยถ
type ConfigManager interface {
// GetConfig retrieves configuration from a source using the specified file and group
GetConfig(fileName string, group string) (config.Source, error)
}
ConfigManager provides configuration management functionality
type ControlPlane ยถ
type ControlPlane interface {
// SystemCore provides basic application information.
SystemCore
// RateLimiter provides rate limiting functionality for HTTP and gRPC services.
RateLimiter
// ServiceRegistry provides service registration and discovery functionality.
ServiceRegistry
// RouteManager provides service routing functionality.
RouteManager
// ConfigManager provides configuration management functionality.
ConfigManager
}
ControlPlane defines the interface for managing core application services including rate limiting, service discovery, routing, and configuration
type DefaultControlPlane ยถ
type DefaultControlPlane struct {
}
DefaultControlPlane provides a basic implementation of the ControlPlane interface for local development and testing purposes
func (*DefaultControlPlane) GRPCRateLimit ยถ
func (c *DefaultControlPlane) GRPCRateLimit() middleware.Middleware
GRPCRateLimit implements the RateLimiter interface for gRPC rate limiting
func (*DefaultControlPlane) GetConfig ยถ
GetConfig implements the ConfigManager interface for configuration management
func (*DefaultControlPlane) GetNamespace ยถ
func (c *DefaultControlPlane) GetNamespace() string
GetNamespace implements the SystemCore interface for namespace management
func (*DefaultControlPlane) HTTPRateLimit ยถ
func (c *DefaultControlPlane) HTTPRateLimit() middleware.Middleware
HTTPRateLimit implements the RateLimiter interface for HTTP rate limiting
func (*DefaultControlPlane) NewNodeRouter ยถ
func (c *DefaultControlPlane) NewNodeRouter(serviceName string) selector.NodeFilter
NewNodeRouter implements the RouteManager interface for service routing
func (*DefaultControlPlane) NewServiceDiscovery ยถ
func (c *DefaultControlPlane) NewServiceDiscovery() registry.Discovery
NewServiceDiscovery implements the ServiceRegistry interface for service discovery
func (*DefaultControlPlane) NewServiceRegistry ยถ
func (c *DefaultControlPlane) NewServiceRegistry() registry.Registrar
NewServiceRegistry implements the ServiceRegistry interface for service registration
type DefaultPluginManager ยถ
DefaultPluginManager is the generic plugin manager implementation.
func NewPluginManager ยถ
func NewPluginManager[T plugins.Plugin](pluginList ...T) *DefaultPluginManager[T]
NewPluginManager creates a generic plugin manager.
func (*DefaultPluginManager[T]) ClearUnloadFailures ยถ
func (m *DefaultPluginManager[T]) ClearUnloadFailures()
ClearUnloadFailures clears all recorded unload failures
func (*DefaultPluginManager[T]) GetPlugin ยถ
func (m *DefaultPluginManager[T]) GetPlugin(name string) plugins.Plugin
GetPlugin gets a plugin by Name().
func (*DefaultPluginManager[T]) GetResourceStats ยถ
func (m *DefaultPluginManager[T]) GetResourceStats() map[string]any
GetResourceStats Resource helpers.
func (*DefaultPluginManager[T]) GetRuntime ยถ
func (m *DefaultPluginManager[T]) GetRuntime() plugins.Runtime
GetRuntime returns the shared runtime.
func (*DefaultPluginManager[T]) GetUnloadFailures ยถ
func (m *DefaultPluginManager[T]) GetUnloadFailures() []UnloadFailureRecord
GetUnloadFailures returns all recorded plugin unload failures
func (*DefaultPluginManager[T]) ListResources ยถ
func (m *DefaultPluginManager[T]) ListResources() []*plugins.ResourceInfo
func (*DefaultPluginManager[T]) LoadPlugins ยถ
func (m *DefaultPluginManager[T]) LoadPlugins(conf config.Config) error
LoadPlugins loads and starts all plugins.
func (*DefaultPluginManager[T]) LoadPluginsByName ยถ
func (m *DefaultPluginManager[T]) LoadPluginsByName(conf config.Config, pluginNames []string) error
LoadPluginsByName loads a subset of plugins by Name().
func (*DefaultPluginManager[T]) PreparePlug ยถ
PreparePlug bootstraps plugin loading via remote or local configuration files. It initializes and registers plugins based on configuration. If a single plugin fails, it logs the error and skips that plugin, attempting to return other successful items. Returns a list of successfully prepared plugins (possibly empty) and an error only for global failures.
func (*DefaultPluginManager[T]) SetConfig ยถ
func (m *DefaultPluginManager[T]) SetConfig(conf config.Config)
SetConfig sets global config.
func (*DefaultPluginManager[T]) StopPlugin ยถ
func (m *DefaultPluginManager[T]) StopPlugin(pluginName string) error
StopPlugin stops a single plugin by Name().
func (*DefaultPluginManager[T]) TopologicalSort ยถ
func (m *DefaultPluginManager[T]) TopologicalSort(plugs []plugins.Plugin) ([]PluginWithLevel, error)
TopologicalSort sorts a subset of plugins based on required dependencies and calculates an integer level for each plugin. It performs a topological sort on the plugin dependency graph and assigns each plugin a level based on the maximum depth of its dependencies.
Dependency timing: GetDependencies() is called on each plugin before any plugin is initialized. Required dependencies that affect load order must therefore be declared in the plugin constructor (or before this sort runs), not only in InitializeResources. See plugins package README "Dependency declaration timing".
Parameters:
- plugs: slice of plugins to sort and calculate levels for
Returns:
- []PluginWithLevel: sorted plugins with their dependency levels
- error: if there's a circular dependency or other resolution error
func (*DefaultPluginManager[T]) UnloadOrder ยถ added in v1.5.3
func (m *DefaultPluginManager[T]) UnloadOrder(plugs []plugins.Plugin) []plugins.Plugin
UnloadOrder returns a best-effort unload order (dependents first, then dependencies). Only considers required dependencies that exist in plugs; ignores missing deps. Used when TopologicalSort fails so unload order is still dependency-aware. Builds load-order graph (dep -> dependent), runs Kahn; unload order = reverse(load order).
func (*DefaultPluginManager[T]) UnloadPlugins ยถ
func (m *DefaultPluginManager[T]) UnloadPlugins()
UnloadPlugins stops and unloads all plugins with overall timeout protection. Optimized for stability: adds total timeout, parallel unloading, and better error handling.
func (*DefaultPluginManager[T]) UnloadPluginsByName ยถ
func (m *DefaultPluginManager[T]) UnloadPluginsByName(names []string)
UnloadPluginsByName unloads a subset of plugins by Name().
type DefaultRecoveryStrategy ยถ
type DefaultRecoveryStrategy struct {
// contains filtered or unexported fields
}
DefaultRecoveryStrategy implements a basic recovery strategy
func NewDefaultRecoveryStrategy ยถ
func NewDefaultRecoveryStrategy(name string, timeout time.Duration) *DefaultRecoveryStrategy
NewDefaultRecoveryStrategy creates a new default recovery strategy
func (*DefaultRecoveryStrategy) CanRecover ยถ
func (s *DefaultRecoveryStrategy) CanRecover(errorType string, severity ErrorSeverity) bool
CanRecover checks if this strategy can recover from the error
func (*DefaultRecoveryStrategy) GetTimeout ยถ
func (s *DefaultRecoveryStrategy) GetTimeout() time.Duration
GetTimeout returns the recovery timeout
func (*DefaultRecoveryStrategy) Name ยถ
func (s *DefaultRecoveryStrategy) Name() string
Name returns the strategy name
func (*DefaultRecoveryStrategy) Recover ยถ
func (s *DefaultRecoveryStrategy) Recover(ctx context.Context, record ErrorRecord) (bool, error)
Recover attempts to recover from the error
type ErrorCategory ยถ
type ErrorCategory string
ErrorCategory represents error categories for better classification
const ( ErrorCategoryNetwork ErrorCategory = "network" ErrorCategoryDatabase ErrorCategory = "database" ErrorCategoryConfig ErrorCategory = "configuration" ErrorCategoryPlugin ErrorCategory = "plugin" ErrorCategoryResource ErrorCategory = "resource" ErrorCategorySecurity ErrorCategory = "security" ErrorCategoryTimeout ErrorCategory = "timeout" ErrorCategoryValidation ErrorCategory = "validation" ErrorCategorySystem ErrorCategory = "system" )
type ErrorRecord ยถ
type ErrorRecord struct {
Timestamp time.Time
ErrorType string
Category ErrorCategory
Message string
Component string
Severity ErrorSeverity
Context map[string]interface{}
Recovered bool
RecoveryTime *time.Time
// Additional fields
StackTrace string
UserID string
RequestID string
Environment string
Version string
}
ErrorRecord represents a recorded error with enhanced context
type ErrorRecoveryManager ยถ
type ErrorRecoveryManager struct {
// contains filtered or unexported fields
}
ErrorRecoveryManager provides centralized error handling and recovery
func NewErrorRecoveryManager ยถ
func NewErrorRecoveryManager(metrics *metrics.ProductionMetrics) *ErrorRecoveryManager
NewErrorRecoveryManager creates a new error recovery manager
func (*ErrorRecoveryManager) ClearHistory ยถ
func (erm *ErrorRecoveryManager) ClearHistory()
ClearHistory clears error and recovery history
func (*ErrorRecoveryManager) GetErrorHistory ยถ
func (erm *ErrorRecoveryManager) GetErrorHistory() []ErrorRecord
GetErrorHistory returns error history
func (*ErrorRecoveryManager) GetErrorStats ยถ
func (erm *ErrorRecoveryManager) GetErrorStats() map[string]interface{}
GetErrorStats returns error statistics
func (*ErrorRecoveryManager) GetHealthReport ยถ
func (erm *ErrorRecoveryManager) GetHealthReport() map[string]interface{}
GetHealthReport returns a detailed health report
func (*ErrorRecoveryManager) GetRecoveryHistory ยถ
func (erm *ErrorRecoveryManager) GetRecoveryHistory() []RecoveryRecord
GetRecoveryHistory returns recovery history
func (*ErrorRecoveryManager) IsHealthy ยถ
func (erm *ErrorRecoveryManager) IsHealthy() bool
IsHealthy returns the health status of the error recovery manager
func (*ErrorRecoveryManager) RecordError ยถ
func (erm *ErrorRecoveryManager) RecordError(errorType string, category ErrorCategory, message, component string, severity ErrorSeverity, context map[string]interface{})
RecordError records an error with enhanced context and classification
func (*ErrorRecoveryManager) RegisterRecoveryStrategy ยถ
func (erm *ErrorRecoveryManager) RegisterRecoveryStrategy(errorType string, strategy RecoveryStrategy)
RegisterRecoveryStrategy registers a recovery strategy
func (*ErrorRecoveryManager) Stop ยถ
func (erm *ErrorRecoveryManager) Stop()
Stop stops the error recovery manager
type ErrorSeverity ยถ
type ErrorSeverity int
ErrorSeverity represents error severity levels
const ( ErrorSeverityLow ErrorSeverity = iota ErrorSeverityMedium ErrorSeverityHigh ErrorSeverityCritical )
type LynxApp ยถ
type LynxApp struct {
// contains filtered or unexported fields
}
LynxApp represents the main application instance. It serves as the central coordinator for all application components, managing configuration, logging, plugins, and the control plane.
func Lynx ยถ
func Lynx() *LynxApp
Lynx returns the global LynxApp instance. It ensures thread-safe access to the singleton instance.
func NewApp ยถ
NewApp creates a new Lynx application instance with the provided configuration and plugins. It initializes the application with system hostname and bootstrap configuration. Uses sync.Once to ensure thread-safe singleton initialization.
Parameters:
- cfg: Configuration instance
- plugins: Optional list of plugins to initialize with
Returns:
- *LynxApp: Initialized application instance
- error: Any error that occurred during initialization
func (*LynxApp) Certificate ยถ
func (a *LynxApp) Certificate() CertificateProvider
Certificate returns the current application's certificate provider. Returns nil if no certificate provider has been set.
func (*LynxApp) ClearUnloadFailures ยถ
func (a *LynxApp) ClearUnloadFailures()
ClearUnloadFailures clears recorded unload failures
func (*LynxApp) GetControlPlane ยถ
func (a *LynxApp) GetControlPlane() ControlPlane
GetControlPlane returns the current control plane instance
func (*LynxApp) GetControlPlaneConfigSources ยถ
GetControlPlaneConfigSources gets all configuration sources from the control plane This method supports loading multiple configuration files from remote sources
func (*LynxApp) GetGlobalConfig ยถ
GetGlobalConfig returns the global configuration instance. Returns nil if the application is not initialized.
func (*LynxApp) GetPluginManager ยถ
func (a *LynxApp) GetPluginManager() TypedPluginManager
GetPluginManager returns the plugin manager instance. Returns nil if the application is not initialized.
func (*LynxApp) GetResourceStats ยถ
GetResourceStats returns resource statistics from the plugin manager
func (*LynxApp) GetTypedPluginManager ยถ
func (a *LynxApp) GetTypedPluginManager() TypedPluginManager
GetTypedPluginManager returns the typed plugin manager instance. Returns nil if the application is not initialized. This is an alias for GetPluginManager() for backward compatibility.
func (*LynxApp) GetUnloadFailures ยถ
func (a *LynxApp) GetUnloadFailures() []UnloadFailureRecord
GetUnloadFailures returns plugin unload failures for monitoring
func (*LynxApp) InitControlPlaneConfig ยถ
InitControlPlaneConfig initializes the control plane configuration It loads the configuration from the specified source and sets up the global configuration
func (*LynxApp) SetCertificateProvider ยถ
func (a *LynxApp) SetCertificateProvider(provider CertificateProvider)
SetCertificateProvider configures the certificate provider for the application. The provider parameter must implement the CertificateProvider interface.
func (*LynxApp) SetControlPlane ยถ
func (a *LynxApp) SetControlPlane(plane ControlPlane) error
SetControlPlane sets the control plane instance for the application
func (*LynxApp) SetGlobalConfig ยถ
SetGlobalConfig updates the global configuration instance. It properly closes the existing configuration before updating.
type MultiConfigControlPlane ยถ
type MultiConfigControlPlane interface {
ControlPlane
// GetConfigSources retrieves all configuration sources for multi-config loading
GetConfigSources() ([]config.Source, error)
}
MultiConfigControlPlane extends ControlPlane to support multiple configuration sources
type PluginManager ยถ
type PluginManager interface {
// Basic plugin management
LoadPlugins(config.Config) error
UnloadPlugins()
LoadPluginsByName(config.Config, []string) error
UnloadPluginsByName([]string)
GetPlugin(name string) plugins.Plugin
PreparePlug(config config.Config) ([]plugins.Plugin, error)
// Runtime and config
GetRuntime() plugins.Runtime
SetConfig(config.Config)
// Resource operations
StopPlugin(pluginName string) error
GetResourceStats() map[string]any
ListResources() []*plugins.ResourceInfo
// Monitoring operations
GetUnloadFailures() []UnloadFailureRecord
ClearUnloadFailures()
}
PluginManager defines plugin management interfaces. Note: TypedPluginManager is an alias for PluginManager and should be used in all public APIs.
type PluginWithLevel ยถ
PluginWithLevel represents a plugin with its dependency level. The level indicates how deep in the dependency chain this plugin is, with 0 being plugins with no dependencies.
type RateLimiter ยถ
type RateLimiter interface {
// HTTPRateLimit returns middleware for HTTP rate limiting
HTTPRateLimit() middleware.Middleware
// GRPCRateLimit returns middleware for gRPC rate limiting
GRPCRateLimit() middleware.Middleware
}
RateLimiter provides rate limiting functionality for HTTP and gRPC services
type RecoveryRecord ยถ
type RecoveryRecord struct {
Timestamp time.Time
ErrorType string
Component string
Strategy string
Success bool
Duration time.Duration
Message string
}
RecoveryRecord represents a recovery attempt
type RecoveryStrategy ยถ
type RecoveryStrategy interface {
Name() string
CanRecover(errorType string, severity ErrorSeverity) bool
Recover(ctx context.Context, record ErrorRecord) (bool, error)
GetTimeout() time.Duration
}
RecoveryStrategy defines a recovery strategy
type RouteManager ยถ
type RouteManager interface {
// NewNodeRouter creates a new node filter for the specified service
NewNodeRouter(serviceName string) selector.NodeFilter
}
RouteManager provides service routing functionality
type RuntimePlugin ยถ
type RuntimePlugin = TypedRuntimePlugin
RuntimePlugin backward-compatible alias of TypedRuntimePlugin
func NewRuntimePlugin ยถ
func NewRuntimePlugin() *RuntimePlugin
NewRuntimePlugin creates a runtime plugin (backward-compatible)
type ServiceRegistry ยถ
type ServiceRegistry interface {
// NewServiceRegistry creates a new service registrar
NewServiceRegistry() registry.Registrar
// NewServiceDiscovery creates a new service discovery client
NewServiceDiscovery() registry.Discovery
}
ServiceRegistry provides service registration and discovery functionality
type SystemCore ยถ
type SystemCore interface {
// GetNamespace returns the current application control plane namespace
GetNamespace() string
}
SystemCore provides basic application information
type TypedPluginManager ยถ
type TypedPluginManager = PluginManager
TypedPluginManager is an alias for PluginManager.
func NewTypedPluginManager ยถ
func NewTypedPluginManager(pluginList ...plugins.Plugin) TypedPluginManager
NewTypedPluginManager creates a plugin manager with plugins.Plugin as T.
type TypedRuntimePlugin ยถ
type TypedRuntimePlugin struct {
// contains filtered or unexported fields
}
TypedRuntimePlugin generic runtime plugin
func NewTypedRuntimePlugin ยถ
func NewTypedRuntimePlugin() *TypedRuntimePlugin
NewTypedRuntimePlugin creates a new TypedRuntimePlugin instance with default settings.
func (*TypedRuntimePlugin) AddListener ยถ
func (r *TypedRuntimePlugin) AddListener(listener plugins.EventListener, filter *plugins.EventFilter)
AddListener registers a new event listener with optional filters. This method is kept for backward compatibility but delegates to the unified event bus.
func (*TypedRuntimePlugin) AddPluginListener ยถ
func (r *TypedRuntimePlugin) AddPluginListener(pluginName string, listener plugins.EventListener, filter *plugins.EventFilter)
AddPluginListener adds a listener for plugin-specific events
func (*TypedRuntimePlugin) CleanupResources ยถ
func (r *TypedRuntimePlugin) CleanupResources(pluginID string) error
CleanupResources cleans up resources for a specific plugin
func (*TypedRuntimePlugin) Close ยถ
func (r *TypedRuntimePlugin) Close()
Close stops the runtime (optional to call)
func (*TypedRuntimePlugin) EmitEvent ยถ
func (r *TypedRuntimePlugin) EmitEvent(event plugins.PluginEvent)
EmitEvent broadcasts a plugin event to the unified event bus. Event will be processed according to its priority and any active filters.
func (*TypedRuntimePlugin) EmitPluginEvent ยถ
func (r *TypedRuntimePlugin) EmitPluginEvent(pluginName string, eventType string, data map[string]any)
EmitPluginEvent emits a plugin-specific event
func (*TypedRuntimePlugin) GetConfig ยถ
func (r *TypedRuntimePlugin) GetConfig() config.Config
GetConfig returns the plugin configuration manager. Provides access to configuration values and updates. Thread-safe: uses sync.Once to ensure initialization happens only once. Fixed: Replaced double-checked locking with sync.Once for better thread safety.
func (*TypedRuntimePlugin) GetCurrentPluginContext ยถ
func (r *TypedRuntimePlugin) GetCurrentPluginContext() string
GetCurrentPluginContext gets the current plugin context
func (*TypedRuntimePlugin) GetEventHistory ยถ
func (r *TypedRuntimePlugin) GetEventHistory(filter plugins.EventFilter) []plugins.PluginEvent
GetEventHistory retrieves historical events based on filter criteria. This method is kept for backward compatibility but delegates to the unified event bus.
func (*TypedRuntimePlugin) GetEventStats ยถ
func (r *TypedRuntimePlugin) GetEventStats() map[string]any
GetEventStats gets event system statistics
func (*TypedRuntimePlugin) GetLogger ยถ
func (r *TypedRuntimePlugin) GetLogger() log.Logger
GetLogger returns the plugin logger instance. Provides structured logging capabilities.
func (*TypedRuntimePlugin) GetPluginEventHistory ยถ
func (r *TypedRuntimePlugin) GetPluginEventHistory(pluginName string, filter plugins.EventFilter) []plugins.PluginEvent
GetPluginEventHistory gets event history for a specific plugin
func (*TypedRuntimePlugin) GetPrivateResource ยถ
func (r *TypedRuntimePlugin) GetPrivateResource(name string) (any, error)
GetPrivateResource gets a private resource for the current plugin context
func (*TypedRuntimePlugin) GetResource ยถ
func (r *TypedRuntimePlugin) GetResource(name string) (any, error)
GetResource retrieves a shared plugin resource by name. Returns the resource and any error encountered.
func (*TypedRuntimePlugin) GetResourceInfo ยถ
func (r *TypedRuntimePlugin) GetResourceInfo(name string) (*plugins.ResourceInfo, error)
GetResourceInfo gets resource information
func (*TypedRuntimePlugin) GetResourceStats ยถ
func (r *TypedRuntimePlugin) GetResourceStats() map[string]any
GetResourceStats gets resource statistics
func (*TypedRuntimePlugin) GetSharedResource ยถ
func (r *TypedRuntimePlugin) GetSharedResource(name string) (any, error)
GetSharedResource gets a shared resource accessible by all plugins
func (*TypedRuntimePlugin) ListResources ยถ
func (r *TypedRuntimePlugin) ListResources() []*plugins.ResourceInfo
ListResources lists all resources
func (*TypedRuntimePlugin) RegisterPrivateResource ยถ
func (r *TypedRuntimePlugin) RegisterPrivateResource(name string, resource any) error
RegisterPrivateResource registers a private resource for the current plugin context
func (*TypedRuntimePlugin) RegisterResource ยถ
func (r *TypedRuntimePlugin) RegisterResource(name string, resource any) error
RegisterResource registers a resource to be shared with other plugins. Returns an error if registration fails.
func (*TypedRuntimePlugin) RegisterSharedResource ยถ
func (r *TypedRuntimePlugin) RegisterSharedResource(name string, resource any) error
RegisterSharedResource registers a shared resource accessible by all plugins
func (*TypedRuntimePlugin) RemoveListener ยถ
func (r *TypedRuntimePlugin) RemoveListener(listener plugins.EventListener)
RemoveListener unregisters an event listener. This method is kept for backward compatibility but delegates to the unified event bus.
func (*TypedRuntimePlugin) SetConfig ยถ
func (r *TypedRuntimePlugin) SetConfig(conf config.Config)
SetConfig sets the configuration
func (*TypedRuntimePlugin) SetEventDispatchMode ยถ
func (r *TypedRuntimePlugin) SetEventDispatchMode(mode string) error
SetEventDispatchMode sets the event dispatch mode
func (*TypedRuntimePlugin) SetEventTimeout ยถ
func (r *TypedRuntimePlugin) SetEventTimeout(timeout time.Duration)
SetEventTimeout sets the event processing timeout
func (*TypedRuntimePlugin) SetEventWorkerPoolSize ยถ
func (r *TypedRuntimePlugin) SetEventWorkerPoolSize(size int)
SetEventWorkerPoolSize sets the event worker pool size
func (*TypedRuntimePlugin) WithPluginContext ยถ
func (r *TypedRuntimePlugin) WithPluginContext(pluginName string) plugins.Runtime
WithPluginContext creates a runtime with plugin context
Source Files
ยถ
Directories
ยถ
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
lynx
module
|
|
|
internal
|
|
|
adapters
Package adapters provides internal adapter implementations for the Lynx framework.
|
Package adapters provides internal adapter implementations for the Lynx framework. |
|
config
Package config provides a minimal validation framework used by plugins and core.
|
Package config provides a minimal validation framework used by plugins and core. |
|
resource
Package resource provides simple runtime resources used by other components.
|
Package resource provides simple runtime resources used by other components. |
|
Package kratos provides integration with the Kratos framework
|
Package kratos provides integration with the Kratos framework |
|
Package log provides a unified logging interface for the Lynx framework.
|
Package log provides a unified logging interface for the Lynx framework. |
|
observability
|
|
|
pkg
|
|
|
config
Package config provides a minimal validation framework used by plugins and core.
|
Package config provides a minimal validation framework used by plugins and core. |
|
factory
Package factory provides functionality for creating and managing plugins in the Lynx framework.
|
Package factory provides functionality for creating and managing plugins in the Lynx framework. |
|
Package plugins provides the core plugin system for the Lynx framework.
|
Package plugins provides the core plugin system for the Lynx framework. |
|
db/mysql
module
|
|
|
db/pgsql
module
|
|
|
mq/kafka
module
|
|
|
nosql/redis
module
|
|
|
polaris
module
|
|
|
seata
module
|
|
|
service/grpc
module
|
|
|
service/http
module
|
|
|
sql/base
module
|
|
|
sql/interfaces
module
|
|
|
sql/mysql
module
|
|
|
sql/pgsql
module
|
|
|
swagger
module
|
|
|
tracer
module
|
|