Delete 实现 PreferenceStorage 接口
(ctx context.Context, userID string)
| 98 | |
| 99 | // Delete 实现 PreferenceStorage 接口 |
| 100 | func (fs *FilePreferenceStorage) Delete(ctx context.Context, userID string) error { |
| 101 | fs.mu.Lock() |
| 102 | defer fs.mu.Unlock() |
| 103 | |
| 104 | filePath := filepath.Join(fs.dir, userID+".json") |
| 105 | if err := os.Remove(filePath); err != nil { |
| 106 | if os.IsNotExist(err) { |
| 107 | return nil // 文件不存在视为成功 |
| 108 | } |
| 109 | return fmt.Errorf("failed to delete file: %w", err) |
| 110 | } |
| 111 | |
| 112 | return nil |
| 113 | } |
| 114 | |
| 115 | // List 实现 PreferenceStorage 接口 |
| 116 | func (fs *FilePreferenceStorage) List(ctx context.Context) ([]string, error) { |