From 7106d5a6e7585dce5fdd552cca30063dd352dc23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Mon, 22 Feb 2021 22:54:43 +0100 Subject: Split cache and feed packages --- main.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index abc80fa..86a6ddf 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - "github.com/Necoro/feed2imap-go/internal/feed" + "github.com/Necoro/feed2imap-go/internal/feed/cache" "github.com/Necoro/feed2imap-go/internal/imap" "github.com/Necoro/feed2imap-go/pkg/config" "github.com/Necoro/feed2imap-go/pkg/log" @@ -33,7 +33,8 @@ func init() { flag.BoolVar(&debug, "d", debug, "enable debug output") } -func processFeed(feed *feed.Feed, client *imap.Client, dryRun bool) { +func processFeed(cf cache.CachedFeed, client *imap.Client, dryRun bool) { + feed := cf.Feed() msgs, err := feed.Messages() if err != nil { log.Errorf("Processing items of feed %s: %s", feed.Name, err) @@ -41,7 +42,7 @@ func processFeed(feed *feed.Feed, client *imap.Client, dryRun bool) { } if dryRun || len(msgs) == 0 { - feed.MarkSuccess() + cf.Commit() return } @@ -58,7 +59,7 @@ func processFeed(feed *feed.Feed, client *imap.Client, dryRun bool) { log.Printf("Uploaded %d messages to '%s' @ %s", len(msgs), feed.Name, folder) - feed.MarkSuccess() + cf.Commit() } func run() error { @@ -81,7 +82,7 @@ func run() error { return err } - state, err := feed.NewState(cfg) + state, err := cache.NewState(cfg) if err != nil { return err } @@ -116,9 +117,9 @@ func run() error { } if buildCache { - state.Foreach((*feed.Feed).MarkSuccess) + state.Foreach(cache.CachedFeed.Commit) } else { - state.ForeachGo(func(f *feed.Feed) { + state.ForeachGo(func(f cache.CachedFeed) { processFeed(f, c, dryRun) }) } -- cgit v1.2.3