MCPcopy
hub / github.com/mxpv/podsync / LoadConfig

Function LoadConfig

cmd/podsync/config.go:56–78  ·  view source on GitHub ↗

LoadConfig loads TOML configuration from a file path

(path string)

Source from the content-addressed store, hash-verified

54
55// LoadConfig loads TOML configuration from a file path
56func LoadConfig(path string) (*Config, error) {
57 data, err := os.ReadFile(path)
58 if err != nil {
59 return nil, errors.Wrapf(err, "failed to read config file: %s", path)
60 }
61
62 config := Config{}
63 if err := toml.Unmarshal(data, &config); err != nil {
64 return nil, errors.Wrap(err, "failed to unmarshal toml")
65 }
66
67 for id, f := range config.Feeds {
68 f.ID = id
69 }
70
71 config.applyDefaults(path)
72
73 if err := config.validate(); err != nil {
74 return nil, err
75 }
76
77 return &config, nil
78}
79
80func (c *Config) validate() error {
81 var result *multierror.Error

Callers 6

TestLoadConfigFunction · 0.85
TestLoadEmptyKeyListFunction · 0.85
TestApplyDefaultsFunction · 0.85
TestLoadBadgerConfigFunction · 0.85
mainFunction · 0.85

Calls 2

applyDefaultsMethod · 0.95
validateMethod · 0.95

Tested by 5

TestLoadConfigFunction · 0.68
TestLoadEmptyKeyListFunction · 0.68
TestApplyDefaultsFunction · 0.68
TestLoadBadgerConfigFunction · 0.68