MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / loadConfigFromFile

Function loadConfigFromFile

config/config.go:220–250  ·  view source on GitHub ↗
(file string)

Source from the content-addressed store, hash-verified

218}
219
220func loadConfigFromFile(file string) error {
221 var cnf Configuration
222 _, err := os.Stat(file)
223 if err == nil {
224 f, err := os.Open(file)
225 if err != nil {
226 return err
227 }
228 err = json.NewDecoder(f).Decode(&cnf)
229 if err != nil {
230 return err
231 }
232
233 } else if errors.Is(err, os.ErrNotExist) {
234 logrus.Info("config json not passed, will use env variables")
235 }
236
237 // override config from environment variables
238 err = envconfig.Process("ledgerforge", &cnf)
239 if err != nil {
240 return err
241 }
242
243 err = cnf.validateAndAddDefaults()
244 if err != nil {
245 return err
246 }
247
248 ConfigStore.Store(&cnf)
249 return err
250}
251
252func InitConfig(configFile string) error {
253 logger()

Callers 2

TestLoadConfigFromFileFunction · 0.85
InitConfigFunction · 0.85

Calls 2

InfoMethod · 0.45

Tested by 1

TestLoadConfigFromFileFunction · 0.68