MCPcopy
hub / github.com/spf13/viper / ReadInConfig

Method ReadInConfig

viper.go:1518–1544  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1516func ReadInConfig() error { return v.ReadInConfig() }
1517
1518func (v *Viper) ReadInConfig() error {
1519 v.logger.Info("attempting to read in config file")
1520 filename, err := v.getConfigFile()
1521 if err != nil {
1522 return err
1523 }
1524
1525 if !slices.Contains(SupportedExts, v.getConfigType()) {
1526 return UnsupportedConfigError(v.getConfigType())
1527 }
1528
1529 v.logger.Debug("reading file", "file", filename)
1530 file, err := afero.ReadFile(v.fs, filename)
1531 if err != nil {
1532 return err
1533 }
1534
1535 config := make(map[string]any)
1536
1537 err = v.unmarshalReader(bytes.NewReader(file), config)
1538 if err != nil {
1539 return err
1540 }
1541
1542 v.config = config
1543 return nil
1544}
1545
1546// MergeInConfig merges a new configuration with an existing config.
1547func MergeInConfig() error { return v.MergeInConfig() }

Callers 12

WatchConfigMethod · 0.95
TestReadInConfigFunction · 0.80
TestDirsSearchFunction · 0.80
TestWriteConfigTOMLFunction · 0.80
TestWriteConfigDotEnvFunction · 0.80
TestWriteHiddenFileFunction · 0.80
newViperWithConfigFileFunction · 0.80
ReadInConfigFunction · 0.80
ExampleFinderFunction · 0.80
ExampleFindersFunction · 0.80

Calls 5

getConfigFileMethod · 0.95
getConfigTypeMethod · 0.95
unmarshalReaderMethod · 0.95
UnsupportedConfigErrorTypeAlias · 0.85
DebugMethod · 0.80

Tested by 10

TestReadInConfigFunction · 0.64
TestDirsSearchFunction · 0.64
TestWriteConfigTOMLFunction · 0.64
TestWriteConfigDotEnvFunction · 0.64
TestWriteHiddenFileFunction · 0.64
newViperWithConfigFileFunction · 0.64
ExampleFinderFunction · 0.64
ExampleFindersFunction · 0.64