MCPcopy Create free account
hub / github.com/astercloud/aster / loadFileData

Method loadFileData

pkg/backends/store_backend.go:324–350  ·  view source on GitHub ↗

loadFileData 从 Store 加载文件数据

(ctx context.Context, path string)

Source from the content-addressed store, hash-verified

322
323// loadFileData 从 Store 加载文件数据
324func (b *StoreBackend) loadFileData(ctx context.Context, path string) (*FileData, error) {
325 key := fmt.Sprintf("%s:data:%s", b.namespace, path)
326
327 // 使用 Store 的 Todos 接口作为通用 KV 存储
328 // (这是一个临时方案,理想情况下应该有专门的 KV 存储接口)
329 dataInterface, err := b.store.LoadTodos(ctx, key)
330 if err != nil {
331 return nil, err
332 }
333
334 if dataInterface == nil {
335 return nil, fmt.Errorf("file not found: %s", path)
336 }
337
338 // 反序列化
339 var data FileData
340 jsonData, err := json.Marshal(dataInterface)
341 if err != nil {
342 return nil, err
343 }
344
345 if err := json.Unmarshal(jsonData, &data); err != nil {
346 return nil, err
347 }
348
349 return &data, nil
350}
351
352// saveFileData 保存文件数据到 Store
353func (b *StoreBackend) saveFileData(ctx context.Context, path string, data *FileData) error {

Callers 4

ReadMethod · 0.95
WriteMethod · 0.95
EditMethod · 0.95
GrepRawMethod · 0.95

Calls 1

LoadTodosMethod · 0.65

Tested by

no test coverage detected