mirror of
https://github.com/matt-dunleavy/plugin-manager.git
synced 2025-10-01 10:32:10 +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.
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
// Copyright (C) 2024 Matt Dunleavy. All rights reserved.
|
|
// Use of this source code is subject to the MIT license
|
|
// that can be found in the LICENSE file.
|
|
|
|
package pluginmanager
|
|
|
|
import (
|
|
"plugin"
|
|
"time"
|
|
)
|
|
|
|
type PluginMetadata struct {
|
|
Name string
|
|
Version string
|
|
Dependencies map[string]string
|
|
GoVersion string
|
|
Signature []byte
|
|
}
|
|
|
|
type Plugin interface {
|
|
Metadata() PluginMetadata
|
|
PreLoad() error
|
|
Init() error
|
|
PostLoad() error
|
|
Execute() error
|
|
PreUnload() error
|
|
Shutdown() error
|
|
}
|
|
|
|
type PluginStats struct {
|
|
ExecutionCount int64
|
|
LastExecutionTime time.Duration
|
|
TotalExecutionTime time.Duration
|
|
}
|
|
|
|
const PluginSymbol = "Plugin"
|
|
|
|
func LoadPlugin(path string) (Plugin, error) {
|
|
p, err := plugin.Open(path)
|
|
if err != nil {
|
|
return nil, &PluginError{Op: "open", Err: err}
|
|
}
|
|
|
|
symPlugin, err := p.Lookup(PluginSymbol)
|
|
if err != nil {
|
|
return nil, &PluginError{Op: "lookup", Err: err}
|
|
}
|
|
|
|
plugin, ok := symPlugin.(Plugin)
|
|
if !ok {
|
|
return nil, &PluginError{Op: "assert", Err: ErrInvalidPluginInterface}
|
|
}
|
|
|
|
return plugin, nil
|
|
} |