diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-04-25 11:27:34 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-04-25 11:27:34 +0200 |
commit | d21881150c09986571a563eaf30bc1687787e63f (patch) | |
tree | a5da8a3fdb91a3dcf806b704e20b16616a934801 /internal/yaml | |
parent | c08aff21cd67cc27926a4cb1ca72ffe67e015ebf (diff) | |
download | feed2imap-go-d21881150c09986571a563eaf30bc1687787e63f.tar.gz feed2imap-go-d21881150c09986571a563eaf30bc1687787e63f.tar.bz2 feed2imap-go-d21881150c09986571a563eaf30bc1687787e63f.zip |
Improved caching
Diffstat (limited to 'internal/yaml')
-rw-r--r-- | internal/yaml/yaml.go | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/internal/yaml/yaml.go b/internal/yaml/yaml.go index 9dc2615..23a38ef 100644 --- a/internal/yaml/yaml.go +++ b/internal/yaml/yaml.go @@ -8,6 +8,7 @@ import ( C "github.com/Necoro/feed2imap-go/internal/config" F "github.com/Necoro/feed2imap-go/internal/feed" + "github.com/Necoro/feed2imap-go/internal/log" ) type config struct { @@ -77,7 +78,7 @@ func appTarget(target []string, app string) []string { } // Parse the group structure and populate the `Target` fields in the feeds -func buildFeeds(cfg []configGroupFeed, target []string, feeds F.Feeds) error { +func buildFeeds(cfg []configGroupFeed, target []string, feeds *F.Feeds) error { for idx := range cfg { f := &cfg[idx] // cannot use `_, f := range cfg` as it returns copies(!), but we need the originals target := appTarget(target, f.target()) @@ -91,15 +92,15 @@ func buildFeeds(cfg []configGroupFeed, target []string, feeds F.Feeds) error { return fmt.Errorf("Unnamed feed") } - if _, ok := feeds[name]; ok { + if feeds.Contains(name) { return fmt.Errorf("Duplicate Feed Name '%s'", name) } - feeds[name] = &F.Feed{ + feeds.Set(name, &F.Feed{ Name: f.Feed.Name, Target: target, Url: f.Feed.Url, Options: f.Feed.Options, - } + }) case f.isGroup(): if err := buildFeeds(f.Group.Feeds, target, feeds); err != nil { @@ -111,7 +112,9 @@ func buildFeeds(cfg []configGroupFeed, target []string, feeds F.Feeds) error { return nil } -func Load(path string) (*C.Config, F.Feeds, error) { +func Load(path string) (*C.Config, *F.Feeds, error) { + log.Printf("Reading configuration file '%s'", path) + buf, err := ioutil.ReadFile(path) if err != nil { return nil, nil, fmt.Errorf("while reading '%s': %w", path, err) @@ -122,7 +125,7 @@ func Load(path string) (*C.Config, F.Feeds, error) { return nil, nil, err } - feeds := F.Feeds{} + feeds := F.NewFeeds() if err := buildFeeds(parsedCfg.Feeds, []string{}, feeds); err != nil { return nil, nil, fmt.Errorf("while parsing: %w", err) |