Get 获取单个资源
(ctx context.Context, collection, key string, dest any)
| 370 | |
| 371 | // Get 获取单个资源 |
| 372 | func (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 设置资源 |
| 393 | func (js *JSONStore) Set(ctx context.Context, collection, key string, value any) error { |
nothing calls this directly
no test coverage detected