aboutsummaryrefslogtreecommitdiff
path: root/internal/parse/parse.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-19 22:41:41 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-19 22:41:41 +0200
commited1e06e6d81645fb5fedd89018c30f95b7598f84 (patch)
tree8ea309cee53a96cd01e1c7add435dd3631a2e9e2 /internal/parse/parse.go
parent76f0beb3db5ef7b3ecac6354bc29a76fef27829a (diff)
downloadfeed2imap-go-ed1e06e6d81645fb5fedd89018c30f95b7598f84.tar.gz
feed2imap-go-ed1e06e6d81645fb5fedd89018c30f95b7598f84.tar.bz2
feed2imap-go-ed1e06e6d81645fb5fedd89018c30f95b7598f84.zip
Rename package 'parse' to 'feed'
Diffstat (limited to 'internal/parse/parse.go')
-rw-r--r--internal/parse/parse.go48
1 files changed, 0 insertions, 48 deletions
diff --git a/internal/parse/parse.go b/internal/parse/parse.go
deleted file mode 100644
index ddf1f0f..0000000
--- a/internal/parse/parse.go
+++ /dev/null
@@ -1,48 +0,0 @@
-package parse
-
-import (
- ctxt "context"
- "fmt"
- "sync"
- "time"
-
- "github.com/mmcdole/gofeed"
-
- "github.com/Necoro/feed2imap-go/internal/config"
- "github.com/Necoro/feed2imap-go/internal/log"
-)
-
-func context() (ctxt.Context, ctxt.CancelFunc) {
- return ctxt.WithTimeout(ctxt.Background(), 60*time.Second)
-}
-
-func parseFeed(feed *config.Feed) error {
- ctx, cancel := context()
- defer cancel()
- fp := gofeed.NewParser()
- if _, err := fp.ParseURLWithContext(feed.Url, ctx); err != nil {
- return fmt.Errorf("while fetching %s from %s: %w", feed.Name, feed.Url, err)
- }
-
- return nil
-}
-
-func handleFeed(feed *config.Feed, wg *sync.WaitGroup) {
- defer wg.Done()
- log.Printf("Fetching %s from %s", feed.Name, feed.Url)
-
- if err := parseFeed(feed); err != nil {
- log.Error(err)
- }
-}
-
-func Parse(feeds config.Feeds) {
- var wg sync.WaitGroup
- wg.Add(len(feeds))
-
- for _, feed := range feeds {
- go handleFeed(feed, &wg)
- }
-
- wg.Wait()
-}