Exists 检查资源是否存在
(ctx context.Context, collection, key string)
| 457 | |
| 458 | // Exists 检查资源是否存在 |
| 459 | func (js *JSONStore) Exists(ctx context.Context, collection, key string) (bool, error) { |
| 460 | js.mu.RLock() |
| 461 | defer js.mu.RUnlock() |
| 462 | |
| 463 | path := filepath.Join(js.collectionDir(collection), key+".json") |
| 464 | _, err := os.Stat(path) |
| 465 | if err != nil { |
| 466 | if os.IsNotExist(err) { |
| 467 | return false, nil |
| 468 | } |
| 469 | return false, fmt.Errorf("stat file: %w", err) |
| 470 | } |
| 471 | |
| 472 | return true, nil |
| 473 | } |
| 474 | |
| 475 | // DecodeValue 将 any 解码为具体类型 |
| 476 | func DecodeValue(src any, dest any) error { |
nothing calls this directly
no test coverage detected