mirror of
https://github.com/matt-dunleavy/plugin-manager.git
synced 2025-10-05 00:22:40 +08:00

This commit introduces significant improvements and new features to the plugin manager: - Add plugin discovery system and remote repository support - Implement plugin update system with digital signature verification - Enhance plugin lifecycle hooks (PreLoad, PostLoad, PreUnload) - Improve dependency management with custom version comparison - Introduce lazy loading for optimized plugin performance - Implement comprehensive error handling and logging - Enhance concurrency safety with fine-grained locking - Add plugin statistics tracking - Remove external version comparison dependencies - Improve hot-reload functionality with graceful shutdown - Add SSH key support for remote repositories - Implement Redbean server integration for plugin repositories This update significantly improves the plugin manager's functionality, security, and performance, providing a more robust and flexible system for managing plugins in Go applications.
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"path/filepath"
|
|
|
|
pm "github.com/matt-dunleavy/plugin-manager"
|
|
)
|
|
|
|
func main() {
|
|
// Initialize the plugin manager
|
|
manager, err := pm.NewManager("plugins.json", "./plugins", "public_key.pem")
|
|
if err != nil {
|
|
log.Fatalf("Failed to create plugin manager: %v", err)
|
|
}
|
|
|
|
// Subscribe to plugin events
|
|
manager.SubscribeToEvent("PluginLoaded", func(e pm.Event) {
|
|
fmt.Printf("Plugin loaded: %s\n", e.(pm.PluginLoadedEvent).PluginName)
|
|
})
|
|
|
|
// Load plugins
|
|
plugins := []string{"hello.so", "math.so"}
|
|
for _, plugin := range plugins {
|
|
err := manager.LoadPlugin(filepath.Join("./plugins", plugin))
|
|
if err != nil {
|
|
log.Printf("Failed to load plugin %s: %v", plugin, err)
|
|
}
|
|
}
|
|
|
|
// List loaded plugins
|
|
loadedPlugins := manager.ListPlugins()
|
|
fmt.Println("Loaded plugins:", loadedPlugins)
|
|
|
|
// Execute plugins
|
|
for _, name := range loadedPlugins {
|
|
err := manager.ExecutePlugin(name)
|
|
if err != nil {
|
|
log.Printf("Failed to execute plugin %s: %v", name, err)
|
|
}
|
|
}
|
|
|
|
// Get and print plugin stats
|
|
for _, name := range loadedPlugins {
|
|
stats, err := manager.GetPluginStats(name)
|
|
if err != nil {
|
|
log.Printf("Failed to get stats for plugin %s: %v", name, err)
|
|
} else {
|
|
fmt.Printf("Stats for %s: Executions: %d, Last execution time: %v\n",
|
|
name, stats.ExecutionCount, stats.LastExecutionTime)
|
|
}
|
|
}
|
|
|
|
// Unload a plugin
|
|
err = manager.UnloadPlugin("hello.so")
|
|
if err != nil {
|
|
log.Printf("Failed to unload plugin: %v", err)
|
|
}
|
|
|
|
fmt.Println("Remaining plugins:", manager.ListPlugins())
|
|
} |