mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-06-24 12:07:44 +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.
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package cliproxy
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/router-for-me/CLIProxyAPI/v7/internal/watcher"
|
|
coreauth "github.com/router-for-me/CLIProxyAPI/v7/sdk/cliproxy/auth"
|
|
"github.com/router-for-me/CLIProxyAPI/v7/sdk/config"
|
|
)
|
|
|
|
func defaultWatcherFactory(configPath, authDir string, reload func(*config.Config)) (*WatcherWrapper, error) {
|
|
w, err := watcher.NewWatcher(configPath, authDir, reload)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &WatcherWrapper{
|
|
start: func(ctx context.Context) error {
|
|
return w.Start(ctx)
|
|
},
|
|
stop: func() error {
|
|
return w.Stop()
|
|
},
|
|
setConfig: func(cfg *config.Config) {
|
|
w.SetConfig(cfg)
|
|
},
|
|
snapshotAuths: func() []*coreauth.Auth { return w.SnapshotCoreAuths() },
|
|
setUpdateQueue: func(queue chan<- watcher.AuthUpdate) {
|
|
w.SetAuthUpdateQueue(queue)
|
|
},
|
|
dispatchRuntimeUpdate: func(update watcher.AuthUpdate) bool {
|
|
return w.DispatchRuntimeAuthUpdate(update)
|
|
},
|
|
dispatchPersistedAuth: func(update watcher.AuthUpdate) bool {
|
|
return w.DispatchPersistedAuthUpdate(update)
|
|
},
|
|
setPluginAuthParser: func(parser PluginAuthParser) {
|
|
w.SetPluginAuthParser(parser)
|
|
},
|
|
}, nil
|
|
}
|