diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-04-19 23:46:08 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-04-19 23:46:08 +0200 |
commit | 431a8ddb0c18b0781cba1d01eda3645b361f1b94 (patch) | |
tree | f67e427279e4e50d20c6acfa8ad22b51f2b5f7e6 /internal/config/config.go | |
parent | ed1e06e6d81645fb5fedd89018c30f95b7598f84 (diff) | |
download | feed2imap-go-431a8ddb0c18b0781cba1d01eda3645b361f1b94.tar.gz feed2imap-go-431a8ddb0c18b0781cba1d01eda3645b361f1b94.tar.bz2 feed2imap-go-431a8ddb0c18b0781cba1d01eda3645b361f1b94.zip |
Restructure
Diffstat (limited to '')
-rw-r--r-- | internal/config/config.go | 63 |
1 files changed, 1 insertions, 62 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index fa14315..0cebf34 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,73 +1,12 @@ package config -import ( - "fmt" - "io/ioutil" - "strings" -) - type Map map[string]interface{} -type Feeds map[string]*Feed - -func (f Feeds) String() string { - var b strings.Builder - app := func(a ...interface{}) { - _, _ = fmt.Fprint(&b, a...) - } - app("Feeds [") - - first := true - for k, v := range f { - if !first { - app(", ") - } - app(`"`, k, `"`, ": ") - if v == nil { - app("<nil>") - } else { - _, _ = fmt.Fprintf(&b, "%+v", *v) - } - first = false - } - app("]") - - return b.String() -} type Config struct { GlobalConfig Map - Feeds Feeds } -type Feed struct { - Name string - Target []string `yaml:"-"` - Url string +type Options struct { MinFreq int `yaml:"min-frequency"` InclImages *bool `yaml:"include-images"` } - -func Load(path string) (Config, error) { - var finishedCfg Config - - buf, err := ioutil.ReadFile(path) - if err != nil { - return finishedCfg, fmt.Errorf("while reading '%s': %w", path, err) - } - - var parsedCfg config - if parsedCfg, err = parse(buf); err != nil { - return finishedCfg, err - } - - finishedCfg = Config{ - GlobalConfig: parsedCfg.GlobalConfig, - Feeds: make(Feeds), - } - - if err := buildFeeds(parsedCfg.Feeds, []string{}, finishedCfg.Feeds); err != nil { - return finishedCfg, fmt.Errorf("while parsing: %w", err) - } - - return finishedCfg, nil -} |