update
All checks were successful
Build Multi-Platform Binaries / build (push) Successful in 11m54s

This commit is contained in:
Flik
2025-12-26 17:14:54 +08:00
parent 4623a7f031
commit 549f9aaf26
63 changed files with 10266 additions and 740 deletions

View File

@@ -8,14 +8,16 @@ import (
// Registry 管理可用的 plugins
type Registry struct {
builtin map[string]ProxyHandler // 内置 Go 实现
mu sync.RWMutex
builtin map[string]ProxyHandler // 内置 Go 实现
enabled map[string]bool // 启用状态
mu sync.RWMutex
}
// NewRegistry 创建 plugin 注册表
func NewRegistry() *Registry {
return &Registry{
builtin: make(map[string]ProxyHandler),
enabled: make(map[string]bool),
}
}
@@ -34,6 +36,7 @@ func (r *Registry) RegisterBuiltin(handler ProxyHandler) error {
}
r.builtin[meta.Name] = handler
r.enabled[meta.Name] = true // 默认启用
return nil
}
@@ -44,6 +47,9 @@ func (r *Registry) Get(proxyType string) (ProxyHandler, error) {
// 先查找内置 plugin
if handler, ok := r.builtin[proxyType]; ok {
if !r.enabled[proxyType] {
return nil, fmt.Errorf("plugin %s is disabled", proxyType)
}
return handler, nil
}
@@ -58,10 +64,11 @@ func (r *Registry) List() []PluginInfo {
var plugins []PluginInfo
// 内置 plugins
for _, handler := range r.builtin {
for name, handler := range r.builtin {
plugins = append(plugins, PluginInfo{
Metadata: handler.Metadata(),
Loaded: true,
Enabled: r.enabled[name],
})
}
@@ -91,3 +98,44 @@ func (r *Registry) Close(ctx context.Context) error {
return lastErr
}
// Enable 启用插件
func (r *Registry) Enable(name string) error {
r.mu.Lock()
defer r.mu.Unlock()
if _, ok := r.builtin[name]; !ok {
return fmt.Errorf("plugin %s not found", name)
}
r.enabled[name] = true
return nil
}
// Disable 禁用插件
func (r *Registry) Disable(name string) error {
r.mu.Lock()
defer r.mu.Unlock()
if _, ok := r.builtin[name]; !ok {
return fmt.Errorf("plugin %s not found", name)
}
r.enabled[name] = false
return nil
}
// IsEnabled 检查插件是否启用
func (r *Registry) IsEnabled(name string) bool {
r.mu.RLock()
defer r.mu.RUnlock()
return r.enabled[name]
}
// RegisterAll 批量注册插件
func (r *Registry) RegisterAll(handlers []ProxyHandler) error {
for _, handler := range handlers {
if err := r.RegisterBuiltin(handler); err != nil {
return err
}
}
return nil
}