LoadFile reads a duckgres.yaml file from disk and parses it. Returns the caller-friendly error from os.ReadFile (so a missing file is recognizable via os.IsNotExist) or a wrapped yaml-parsing error.
(path string)
| 11 | // caller-friendly error from os.ReadFile (so a missing file is recognizable |
| 12 | // via os.IsNotExist) or a wrapped yaml-parsing error. |
| 13 | func LoadFile(path string) (*FileConfig, error) { |
| 14 | data, err := os.ReadFile(path) |
| 15 | if err != nil { |
| 16 | return nil, err |
| 17 | } |
| 18 | var cfg FileConfig |
| 19 | if err := yaml.Unmarshal(data, &cfg); err != nil { |
| 20 | return nil, fmt.Errorf("failed to parse config file: %w", err) |
| 21 | } |
| 22 | return &cfg, nil |
| 23 | } |
| 24 | |
| 25 | // Env returns the value of the named environment variable, falling back to |
| 26 | // defaultVal when unset or empty. Shared by every duckgres binary so the |