Files
memoryweave/go/internal/api/server_storage_nowindows.go
小唯 886c0c20e2 style(gofmt): 全仓 66 文件对齐 gofmt 1.25
gofmt -l 实测 66 文件不合规(历史遗留+gofmt 1.25 规范化:
单行 if/for/case 展开成块、Go1.19+ doc 注释 // 与段落 // 空行)。
本 commit 只含格式化,零逻辑改动:
- 66/66 文件「去注释+去空白+分号归一」后 token 流与 HEAD 完全一致
- go build ./... exit 0;go vet ./... exit 0(改前后一致)
- go test ./... 17 包全 ok(改前后一致)
验收: gofmt -l . 为空;git diff -w 非空系 gofmt 1.25 非纯空白特性,
非逻辑改动(等价性以 token 流 + test 兜底)。
2026-10-10 15:51:25 +08:00

57 lines
1.7 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//go:build !windows
// 织忆 MemoryWeave — 存储+图谱初始化(非 Windows,SQLite CGO 可用)
package api
import (
"log"
"os"
"github.com/xiaoxue/memoryweave/internal/governance"
"github.com/xiaoxue/memoryweave/internal/storage"
)
// initStorageBackend 初始化存储后端(非 Windows:LanceDB + SQLite + 内存)
func initStorageBackend(backend string, emb *storage.Embedder) storage.LanceDB {
switch backend {
case "lancedb":
sockPath := os.Getenv("LANCEDB_SOCKET")
if sockPath == "" {
sockPath = "/tmp/zhiyi-ipc.sock"
}
ldb := storage.NewRustLanceDBClient(sockPath, emb)
log.Printf("[zhiyid] 存储后端: LanceDB (Rust IPC) — %s", sockPath)
return ldb
case "sqlite":
dbPath := os.Getenv("SQLITE_PATH")
if dbPath == "" {
dbPath = "/var/lib/memoryweave/zhiyi.db"
}
sqliteDB, err := storage.NewSQLiteClient(dbPath)
if err != nil {
log.Printf("[zhiyid] SQLite 初始化失败 (%v),降级为内存存储", err)
return storage.NewMemLanceClient(emb)
}
log.Printf("[zhiyid] 存储后端: SQLite (CGO) — %s", dbPath)
return sqliteDB
default:
log.Printf("[zhiyid] 存储后端: 内存(零依赖)")
return storage.NewMemLanceClient(emb)
}
}
// initGraphStore 初始化图谱(非 Windows:SQLite 图谱 + 内存降级)
func initGraphStore() governance.GraphStore {
graphPath := os.Getenv("GRAPH_PATH")
if graphPath == "" {
graphPath = "/var/lib/memoryweave/graph.db"
}
gs, err := governance.NewSQLiteGraphStore(graphPath)
if err != nil {
log.Printf("[zhiyid] WARN: SQLite 图谱初始化失败 (%v),降级为 InMemoryGraph", err)
return governance.NewInMemoryGraph()
}
log.Printf("[zhiyid] 图谱后端: SQLiteGraphStore — %s", graphPath)
return gs
}