Files
CLIProxyAPI/sdk/cliproxy/kv_store.go
Luis Pater ec14dc4703 feat(kvstore): add local bbolt key-value store and integration routing
- 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.
2026-11-04 23:21:53 +08:00

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()
}