LoadAppConfig loads config from path. Returns nil, nil if file does not exist.
(path string)
| 332 | |
| 333 | // LoadAppConfig loads config from path. Returns nil, nil if file does not exist. |
| 334 | func LoadAppConfig(path string) (*Config, error) { |
| 335 | data, err := os.ReadFile(path) |
| 336 | if err != nil { |
| 337 | if os.IsNotExist(err) { |
| 338 | return nil, nil |
| 339 | } |
| 340 | return nil, fmt.Errorf("read app config %s: %w", path, err) |
| 341 | } |
| 342 | var cfg Config |
| 343 | if err := json.Unmarshal(data, &cfg); err != nil { |
| 344 | return nil, fmt.Errorf("parse app config: %w", err) |
| 345 | } |
| 346 | return &cfg, nil |
| 347 | } |
| 348 | |
| 349 | // supportedConfigKeys is the single source of truth for the top-level config |
| 350 | // keys accepted by setConfigValue. The unknown-key error message is generated |
no outgoing calls