--- legacy CAM-config helpers (operate on the file at --config) ---------
(path string)
| 283 | // --- legacy CAM-config helpers (operate on the file at --config) --------- |
| 284 | |
| 285 | func loadConfigFile(path string) (map[string]any, error) { |
| 286 | data, err := os.ReadFile(path) |
| 287 | if err != nil { |
| 288 | return nil, fmt.Errorf("failed to read config %s: %w", path, err) |
| 289 | } |
| 290 | cfg := map[string]any{} |
| 291 | switch strings.ToLower(filepath.Ext(path)) { |
| 292 | case ".json": |
| 293 | err = json.Unmarshal(data, &cfg) |
| 294 | case ".toml": |
| 295 | err = toml.Unmarshal(data, &cfg) |
| 296 | default: |
| 297 | err = yaml.Unmarshal(data, &cfg) |
| 298 | } |
| 299 | if err != nil { |
| 300 | return nil, fmt.Errorf("failed to parse config %s: %w", path, err) |
| 301 | } |
| 302 | return cfg, nil |
| 303 | } |
| 304 | |
| 305 | func writeConfigFile(path string, cfg map[string]any) error { |
| 306 | var data []byte |
no test coverage detected