diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-04-18 00:44:04 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-04-18 00:44:04 +0200 |
commit | 1dffefe667760113d23f89e65b066a78b9d7e0b0 (patch) | |
tree | 41f7d4485f7fd98838215f99ef66dc57092bcfb1 /internal/config/config.go | |
parent | 5b1a3c9c54652f4ed70677729ccaeabb498f0954 (diff) | |
download | feed2imap-go-1dffefe667760113d23f89e65b066a78b9d7e0b0.tar.gz feed2imap-go-1dffefe667760113d23f89e65b066a78b9d7e0b0.tar.bz2 feed2imap-go-1dffefe667760113d23f89e65b066a78b9d7e0b0.zip |
Tests
Diffstat (limited to 'internal/config/config.go')
-rw-r--r-- | internal/config/config.go | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 2df7d98..361246e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,51 +2,46 @@ package config import ( "fmt" - "gopkg.in/yaml.v3" "io/ioutil" ) type Map map[string]interface{} type Feeds map[string]*Feed -type config struct { - GlobalConfig Map `yaml:",inline"` - Feeds []configGroupFeed -} - type Config struct { - GlobalConfig Map `yaml:",inline"` + GlobalConfig Map Feeds Feeds } type Feed struct { - Name string - Target string - Url string - MinFreq int - Config Map + Name string + Target string `yaml:"-"` + Url string + MinFreq int `yaml:"min-frequency"` + InclImages *bool `yaml:"include-images"` } -func Load(path string) (*Config, error) { +func Load(path string) (Config, error) { + var finishedCfg Config + buf, err := ioutil.ReadFile(path) if err != nil { - return nil, fmt.Errorf("while reading '%s': %w", path, err) + return finishedCfg, fmt.Errorf("while reading '%s': %w", path, err) } var parsedCfg config - if err := yaml.Unmarshal(buf, &parsedCfg); err != nil { - return nil, fmt.Errorf("while unmarshalling: %w", err) + if parsedCfg, err = parse(buf); err != nil { + return finishedCfg, err } - fmt.Printf("--- parsedCfg:\n%+v\n\n", parsedCfg) - var finishedCfg = Config{ + finishedCfg = Config{ GlobalConfig: parsedCfg.GlobalConfig, Feeds: make(Feeds), } if err := buildFeeds(parsedCfg.Feeds, "", finishedCfg.Feeds); err != nil { - return nil, fmt.Errorf("while parsing: %w", err) + return finishedCfg, fmt.Errorf("while parsing: %w", err) } - return &finishedCfg, nil + return finishedCfg, nil } |