loadConfigFile reads and parses the config file at the given path, or at the OS-specific default location if configPath is empty.
(configPath string)
| 144 | // loadConfigFile reads and parses the config file at the given path, |
| 145 | // or at the OS-specific default location if configPath is empty. |
| 146 | func loadConfigFile(configPath string) (*fileConfig, error) { |
| 147 | path, err := resolveConfigPath(configPath) |
| 148 | if err != nil { |
| 149 | return nil, err |
| 150 | } |
| 151 | |
| 152 | data, err := os.ReadFile(path) |
| 153 | if err != nil { |
| 154 | return nil, fmt.Errorf("error reading %s: %v", path, err) |
| 155 | } |
| 156 | |
| 157 | var cfg fileConfig |
| 158 | err = yaml.Unmarshal(data, &cfg) |
| 159 | if err != nil { |
| 160 | return nil, fmt.Errorf("error parsing %s: %v", path, err) |
| 161 | } |
| 162 | return &cfg, nil |
| 163 | } |
| 164 | |
| 165 | // handleValidateConfig reads the config file and validates its contents. |
| 166 | // If configPath is empty, the OS-specific default location is used. |
no test coverage detected