mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-22 16:43:50 +08:00
- Implemented command-line flag registration and execution for plugins with priority-based conflict resolution. - Enabled plugin-owned command-line flag execution and persistence of plugin-auth data. - Added new `Host` methods to support command-line capabilities, including flag normalization, validation, and execution state management. - Introduced unit tests to ensure coverage for command-line plugin functionality, including auth data persistence. - Updated configs to normalize plugins during initialization.
36 lines
658 B
Go
36 lines
658 B
Go
//go:build linux || darwin || freebsd
|
|
|
|
package pluginhost
|
|
|
|
import "plugin"
|
|
|
|
type symbolLoader interface {
|
|
Open(path string) (symbolLookup, error)
|
|
}
|
|
|
|
type symbolLookup interface {
|
|
Lookup(name string) (any, error)
|
|
}
|
|
|
|
type goPluginLoader struct{}
|
|
|
|
func (goPluginLoader) Open(path string) (symbolLookup, error) {
|
|
opened, errOpen := plugin.Open(path)
|
|
if errOpen != nil {
|
|
return nil, errOpen
|
|
}
|
|
return goPluginLookup{plugin: opened}, nil
|
|
}
|
|
|
|
type goPluginLookup struct {
|
|
plugin *plugin.Plugin
|
|
}
|
|
|
|
func (l goPluginLookup) Lookup(name string) (any, error) {
|
|
return l.plugin.Lookup(name)
|
|
}
|
|
|
|
func defaultSymbolLoader() symbolLoader {
|
|
return goPluginLoader{}
|
|
}
|