mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
36 lines
942 B
Go
36 lines
942 B
Go
package cliproxy
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/watcher"
|
|
coreauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
|
|
)
|
|
|
|
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)
|
|
},
|
|
}, nil
|
|
}
|