(configDir string)
| 131 | } |
| 132 | |
| 133 | func load(configDir string) (*configfile.ConfigFile, error) { |
| 134 | filename := filepath.Join(configDir, ConfigFileName) |
| 135 | configFile := configfile.New(filename) |
| 136 | |
| 137 | file, err := os.Open(filename) |
| 138 | if err != nil { |
| 139 | if os.IsNotExist(err) { |
| 140 | // It is OK for no configuration file to be present, in which |
| 141 | // case we return a default struct. |
| 142 | return configFile, nil |
| 143 | } |
| 144 | // Any other error happening when failing to read the file must be returned. |
| 145 | return configFile, fmt.Errorf("loading config file: %w", err) |
| 146 | } |
| 147 | defer func() { _ = file.Close() }() |
| 148 | err = configFile.LoadFromReader(file) |
| 149 | if err != nil { |
| 150 | err = fmt.Errorf("parsing config file (%s): %w", filename, err) |
| 151 | } |
| 152 | return configFile, err |
| 153 | } |
| 154 | |
| 155 | // LoadDefaultConfigFile attempts to load the default config file and returns |
| 156 | // a reference to the ConfigFile struct. If none is found or when failing to load |
no test coverage detected
searching dependent graphs…