LoadAppConfig loads config from path. Returns nil, nil if file does not exist.
(path string)
| 400 | |
| 401 | // LoadAppConfig loads config from path. Returns nil, nil if file does not exist. |
| 402 | func LoadAppConfig(path string) (*Config, error) { |
| 403 | data, err := os.ReadFile(path) |
| 404 | if err != nil { |
| 405 | if os.IsNotExist(err) { |
| 406 | return nil, nil |
| 407 | } |
| 408 | return nil, fmt.Errorf("read app config %s: %w", path, err) |
| 409 | } |
| 410 | var cfg Config |
| 411 | if err := json.Unmarshal(data, &cfg); err != nil { |
| 412 | return nil, fmt.Errorf("parse app config: %w", err) |
| 413 | } |
| 414 | return &cfg, nil |
| 415 | } |
| 416 | |
| 417 | // supportedConfigKeys is the single source of truth for the top-level config |
| 418 | // keys accepted by setConfigValue. The unknown-key error message is generated |
no outgoing calls