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

Method Get

pkg/store/json.go:372–390  ·  view source on GitHub ↗

Get 获取单个资源

(ctx context.Context, collection, key string, dest any)

Source from the content-addressed store, hash-verified

370
371// Get 获取单个资源
372func (js *JSONStore) Get(ctx context.Context, collection, key string, dest any) error {
373 js.mu.RLock()
374 defer js.mu.RUnlock()
375
376 path := filepath.Join(js.collectionDir(collection), key+".json")
377 data, err := os.ReadFile(path)
378 if err != nil {
379 if os.IsNotExist(err) {
380 return ErrNotFound
381 }
382 return fmt.Errorf("read file: %w", err)
383 }
384
385 if err := json.Unmarshal(data, dest); err != nil {
386 return fmt.Errorf("unmarshal json: %w", err)
387 }
388
389 return nil
390}
391
392// Set 设置资源
393func (js *JSONStore) Set(ctx context.Context, collection, key string, value any) error {

Callers

nothing calls this directly

Calls 3

collectionDirMethod · 0.95
JoinMethod · 0.45
ReadFileMethod · 0.45

Tested by

no test coverage detected