ReadFileConfig attempts to read the config file at the specified path and returns a config object, using the default config if the file was unable to be read.
(afs afero.Fs, path string)
| 151 | // ReadFileConfig attempts to read the config file at the specified path and |
| 152 | // returns a config object, using the default config if the file was unable to be read. |
| 153 | func ReadFileConfig(afs afero.Fs, path string) (*Config, error) { |
| 154 | // read the config file |
| 155 | contents, err := util.GetFileContents(afs, path) |
| 156 | if err != nil { |
| 157 | return nil, err |
| 158 | } |
| 159 | // fmt.Println("contents:", contents) |
| 160 | var cfg Config |
| 161 | // // parse the JSON config file |
| 162 | // if err := hjson.Unmarshal(contents, &cfg); err != nil { |
| 163 | // return nil, err |
| 164 | // } |
| 165 | if err := unmarshal(contents, &cfg, nil); err != nil { |
| 166 | return nil, fmt.Errorf("%w, located by default at '%s', please correct the issue in the config and try again:\n\t- %w", errReadingConfigFile, path, err) |
| 167 | } |
| 168 | // // set the environment variables |
| 169 | // if err := setEnv(&cfg); err != nil { |
| 170 | // return nil, fmt.Errorf("unable to set environment: %w", err) |
| 171 | // } |
| 172 | |
| 173 | return &cfg, nil |
| 174 | } |
| 175 | |
| 176 | // ReadConfigFromMemory reads the config from bytes already read into memory as opposed to reading from a file |
| 177 | // It also provides its own environment struct that must already be completely set |