Add tags to rss struct
parent
440ebcc54a
commit
03befc13d1
9
main.go
9
main.go
|
|
@ -32,7 +32,7 @@ func core() {
|
|||
mon, err := monitor.New(func(url string) {
|
||||
feed, ok := allFeeds[url]
|
||||
if !ok {
|
||||
f, err := rss.New(url, "", "", time.Minute)
|
||||
f, err := rss.New(url, "", "", nil, time.Minute)
|
||||
if err != nil {
|
||||
logger.Logf("cannot identify unknown feed triggered in monitor: %q: %v", url, err)
|
||||
return
|
||||
|
|
@ -85,8 +85,8 @@ func core() {
|
|||
defer mon.Stop()
|
||||
|
||||
server, err := server.New(config.Port,
|
||||
func(url string, itemFilter, contentFilter string, interval time.Duration) {
|
||||
feed, err := rss.New(url, itemFilter, contentFilter, interval)
|
||||
func(url string, itemFilter, contentFilter string, tags []string, interval time.Duration) {
|
||||
feed, err := rss.New(url, itemFilter, contentFilter, tags, interval)
|
||||
if err != nil {
|
||||
logger.Logf("can't create new RSS %q: %v", url, err)
|
||||
return
|
||||
|
|
@ -129,6 +129,9 @@ func core() {
|
|||
}
|
||||
return item.Content, nil
|
||||
},
|
||||
func(tag string) (string, error) {
|
||||
return "", errors.New("not implemented")
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ type Feed struct {
|
|||
Updated time.Time
|
||||
Title string
|
||||
Items []string
|
||||
Tags []string
|
||||
ItemFilter string
|
||||
ContentFilter string
|
||||
Link string
|
||||
|
|
@ -24,7 +25,7 @@ type Feed struct {
|
|||
}
|
||||
|
||||
func (feed *Feed) String() string {
|
||||
return fmt.Sprintf("Title: %s, Updated: %v, Items: %v, ItemFilter: %q, ContentFilter: %q, Link: %v, Interval: %s",
|
||||
return fmt.Sprintf("Title: %s, Updated: %v, Items: %v, ItemFilter: %q, ContentFilter: %q, Link: %v, Interval: %s, Tags: %v",
|
||||
feed.Title,
|
||||
feed.Updated.Local(),
|
||||
feed.Items,
|
||||
|
|
@ -32,6 +33,7 @@ func (feed *Feed) String() string {
|
|||
feed.ContentFilter,
|
||||
feed.Link,
|
||||
feed.Interval,
|
||||
feed.Tags,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -39,7 +41,7 @@ func (feed *Feed) ID() string {
|
|||
return strings.Join(regexp.MustCompile("[a-zA-Z0-9]*").FindAllString(feed.Link, -1), "_")
|
||||
}
|
||||
|
||||
func New(source, itemFilter, contentFilter string, interval time.Duration) (*Feed, error) {
|
||||
func New(source, itemFilter, contentFilter string, tags []string, interval time.Duration) (*Feed, error) {
|
||||
if _, err := regexp.Compile(itemFilter); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -51,6 +53,7 @@ func New(source, itemFilter, contentFilter string, interval time.Duration) (*Fee
|
|||
ItemFilter: itemFilter,
|
||||
ContentFilter: contentFilter,
|
||||
Link: source,
|
||||
Tags: tags,
|
||||
Interval: interval,
|
||||
}
|
||||
return f, nil
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ func Test_RSSFeed(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
feed, err := New(s.URL, c.itemFilter, c.contentFilter, time.Minute)
|
||||
feed, err := New(s.URL, c.itemFilter, c.contentFilter, nil, time.Minute)
|
||||
if err != nil {
|
||||
t.Errorf("couldn't create new feed %v: %v", feed, err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue