aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/feed.go
blob: cd906a2d17420286a03cd08dbc347bf165146760 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
	items []feeditem
}

type feeditem struct {
	*gofeed.Feed
	*gofeed.Item
}

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()
}