NewManager 创建 Memory 管理器
(cfg *ManagerConfig)
| 54 | |
| 55 | // NewManager 创建 Memory 管理器 |
| 56 | func NewManager(cfg *ManagerConfig) (*Manager, error) { |
| 57 | if cfg == nil { |
| 58 | return nil, errors.New("memory.ManagerConfig cannot be nil") |
| 59 | } |
| 60 | if cfg.Backend == nil { |
| 61 | return nil, errors.New("memory.Manager requires a non-nil Backend") |
| 62 | } |
| 63 | |
| 64 | memoryPath := cfg.MemoryPath |
| 65 | if memoryPath == "" { |
| 66 | memoryPath = "/memories/" |
| 67 | } |
| 68 | |
| 69 | // 规范化路径,统一为以 / 开头,以 / 结尾 |
| 70 | memoryPath = normalizeDir(memoryPath) |
| 71 | |
| 72 | return &Manager{ |
| 73 | backend: cfg.Backend, |
| 74 | memoryPath: memoryPath, |
| 75 | }, nil |
| 76 | } |
| 77 | |
| 78 | // MemoryPath 返回记忆根路径 |
| 79 | func (m *Manager) MemoryPath() string { |
no test coverage detected