List 实现 PreferenceStorage 接口
(ctx context.Context)
| 114 | |
| 115 | // List 实现 PreferenceStorage 接口 |
| 116 | func (fs *FilePreferenceStorage) List(ctx context.Context) ([]string, error) { |
| 117 | fs.mu.RLock() |
| 118 | defer fs.mu.RUnlock() |
| 119 | |
| 120 | entries, err := os.ReadDir(fs.dir) |
| 121 | if err != nil { |
| 122 | return nil, fmt.Errorf("failed to read directory: %w", err) |
| 123 | } |
| 124 | |
| 125 | userIDs := []string{} |
| 126 | for _, entry := range entries { |
| 127 | if entry.IsDir() { |
| 128 | continue |
| 129 | } |
| 130 | |
| 131 | // 提取用户 ID(移除 .json 后缀) |
| 132 | name := entry.Name() |
| 133 | if filepath.Ext(name) == ".json" { |
| 134 | userID := name[:len(name)-5] // 移除 ".json" |
| 135 | userIDs = append(userIDs, userID) |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return userIDs, nil |
| 140 | } |
| 141 | |
| 142 | // PersistentPreferenceManager 带持久化的偏好管理器 |
| 143 | type PersistentPreferenceManager struct { |