aboutsummaryrefslogtreecommitdiff
path: root/internal/feed
diff options
context:
space:
mode:
Diffstat (limited to 'internal/feed')
-rw-r--r--internal/feed/feed.go45
-rw-r--r--internal/feed/parse.go7
2 files changed, 48 insertions, 4 deletions
diff --git a/internal/feed/feed.go b/internal/feed/feed.go
new file mode 100644
index 0000000..59c15f2
--- /dev/null
+++ b/internal/feed/feed.go
@@ -0,0 +1,45 @@
+package feed
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/mmcdole/gofeed"
+
+ "github.com/Necoro/feed2imap-go/internal/config"
+)
+
+type Feed struct {
+ Name string
+ Target []string
+ Url string
+ config.Options
+ feed gofeed.Feed
+}
+
+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()
+}
diff --git a/internal/feed/parse.go b/internal/feed/parse.go
index 53ceb00..a38be92 100644
--- a/internal/feed/parse.go
+++ b/internal/feed/parse.go
@@ -8,7 +8,6 @@ import (
"github.com/mmcdole/gofeed"
- "github.com/Necoro/feed2imap-go/internal/config"
"github.com/Necoro/feed2imap-go/internal/log"
)
@@ -16,7 +15,7 @@ func context() (ctxt.Context, ctxt.CancelFunc) {
return ctxt.WithTimeout(ctxt.Background(), 60*time.Second)
}
-func parseFeed(feed *config.Feed) error {
+func parseFeed(feed *Feed) error {
ctx, cancel := context()
defer cancel()
fp := gofeed.NewParser()
@@ -27,7 +26,7 @@ func parseFeed(feed *config.Feed) error {
return nil
}
-func handleFeed(feed *config.Feed, wg *sync.WaitGroup) {
+func handleFeed(feed *Feed, wg *sync.WaitGroup) {
defer wg.Done()
log.Printf("Fetching %s from %s", feed.Name, feed.Url)
@@ -36,7 +35,7 @@ func handleFeed(feed *config.Feed, wg *sync.WaitGroup) {
}
}
-func Parse(feeds config.Feeds) {
+func Parse(feeds Feeds) {
var wg sync.WaitGroup
wg.Add(len(feeds))