aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/feed.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-25 17:00:57 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-25 17:00:57 +0200
commit573ce1982da2e754947453fdaf0d50204873acb4 (patch)
treef6528235dce77db514ce4442ee8817e993fdcc86 /internal/feed/feed.go
parentd21881150c09986571a563eaf30bc1687787e63f (diff)
downloadfeed2imap-go-573ce1982da2e754947453fdaf0d50204873acb4.tar.gz
feed2imap-go-573ce1982da2e754947453fdaf0d50204873acb4.tar.bz2
feed2imap-go-573ce1982da2e754947453fdaf0d50204873acb4.zip
Larger restructuring
Diffstat (limited to '')
-rw-r--r--internal/feed/feed.go80
1 files changed, 8 insertions, 72 deletions
diff --git a/internal/feed/feed.go b/internal/feed/feed.go
index 5af4188..c7fdd5f 100644
--- a/internal/feed/feed.go
+++ b/internal/feed/feed.go
@@ -1,22 +1,16 @@
package feed
import (
- "fmt"
- "strings"
- "sync"
"time"
"github.com/mmcdole/gofeed"
- "github.com/Necoro/feed2imap-go/internal/config"
- "github.com/Necoro/feed2imap-go/internal/log"
+ "github.com/Necoro/feed2imap-go/pkg/config"
+ "github.com/Necoro/feed2imap-go/pkg/log"
)
type Feed struct {
- Name string
- Target []string
- Url string
- config.Options
+ config.Feed
feed *gofeed.Feed
items []feeditem
cached CachedFeed
@@ -27,73 +21,15 @@ type feeditem struct {
*gofeed.Item
}
-type Feeds struct {
- feeds map[string]*Feed
- cache Cache
-}
-
-func NewFeeds() *Feeds {
- return &Feeds{
- feeds: map[string]*Feed{},
- }
-}
-
-func (feeds *Feeds) String() string {
- var b strings.Builder
- app := func(a ...interface{}) {
- _, _ = fmt.Fprint(&b, a...)
- }
- app("Feeds [")
-
- first := true
- for k, v := range feeds.feeds {
- if !first {
- app(", ")
- }
- app(`"`, k, `"`, ": ")
- if v == nil {
- app("<nil>")
- } else {
- _, _ = fmt.Fprintf(&b, "%+v", *v)
- }
- first = false
- }
- app("]")
-
- return b.String()
-}
-
-func (feeds *Feeds) Len() int {
- return len(feeds.feeds)
-}
-
-func (feeds *Feeds) Contains(name string) bool {
- _, ok := feeds.feeds[name]
- return ok
-}
-
-func (feeds *Feeds) Set(name string, feed *Feed) {
- feeds.feeds[name] = feed
-}
-
-func (feeds *Feeds) Foreach(f func(*Feed)) {
- for _, feed := range feeds.feeds {
- f(feed)
- }
-}
-
-func (feeds *Feeds) ForeachGo(goFunc func(*Feed, *sync.WaitGroup)) {
- var wg sync.WaitGroup
- wg.Add(feeds.Len())
-
- for _, feed := range feeds.feeds {
- go goFunc(feed, &wg)
+func (feed *Feed) descriptor() feedDescriptor {
+ return feedDescriptor{
+ Name: feed.Name,
+ Url: feed.Url,
}
- wg.Wait()
}
func (feed *Feed) NeedsUpdate(updateTime time.Time) bool {
- if !updateTime.IsZero() && int(time.Since(updateTime).Hours()) >= feed.MinFreq {
+ if !updateTime.IsZero() && int(time.Since(updateTime).Hours()) >= *feed.MinFreq {
log.Printf("Feed '%s' does not need updating, skipping.", feed.Name)
return false
}