mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-19 16:29:45 +08:00
- Add `kvstore` package supporting local bbolt-backed key-value storage with automatic path normalization and lifecycle management. - Implement controller routing order in `CurrentKVClient` to prioritize active Home KV over local bbolt storage and fall back to in-memory mode. - Refactor home key-value helpers to delegate shared logic to the new `kvstore` package.
34 lines
935 B
Go
34 lines
935 B
Go
package cliproxy
|
|
|
|
import (
|
|
"github.com/router-for-me/CLIProxyAPI/v8/internal/config"
|
|
"github.com/router-for-me/CLIProxyAPI/v8/internal/home"
|
|
"github.com/router-for-me/CLIProxyAPI/v8/internal/kvstore"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func (s *Service) applyKVStoreConfig(cfg *config.Config) {
|
|
if s == nil {
|
|
if errShutdown := kvstore.ShutdownLocal(); errShutdown != nil {
|
|
log.Errorf("failed to shutdown local kv store: %v", errShutdown)
|
|
}
|
|
return
|
|
}
|
|
s.kvStoreManaged.Store(true)
|
|
if cfg == nil || cfg.Home.Enabled || home.Current() != nil || cfg.KVStore.Disabled {
|
|
if errShutdown := kvstore.ShutdownLocal(); errShutdown != nil {
|
|
log.Errorf("failed to shutdown local kv store: %v", errShutdown)
|
|
}
|
|
return
|
|
}
|
|
_ = kvstore.ConfigureLocal(true, cfg.EffectiveKVStorePath())
|
|
}
|
|
|
|
func (s *Service) shutdownKVStore() error {
|
|
if s == nil {
|
|
return nil
|
|
}
|
|
s.kvStoreManaged.Store(false)
|
|
return kvstore.ShutdownLocal()
|
|
}
|