From 75bec51affee1f01d107e68b38180c9d5d5edae0 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 21 Dec 2016 00:38:25 +0100 Subject: Split feeds --- rss.go | 66 ++++-------------------------------------------------------------- 1 file changed, 4 insertions(+), 62 deletions(-) (limited to 'rss.go') diff --git a/rss.go b/rss.go index 741b81d..6f5239b 100644 --- a/rss.go +++ b/rss.go @@ -14,64 +14,6 @@ type Feed struct { Every time.Duration } -var Feeds = []Feed{ - { - Name: "LOR News", - URL: `https://www.linux.org.ru/section-rss.jsp?section=1`, - Every: time.Hour, - }, - { - Name: "LOR Forum", - URL: `https://www.linux.org.ru/section-rss.jsp?section=2&filter=tech`, - Every: time.Minute, - }, - { - Name: "LOR Gallery", - URL: `https://www.linux.org.ru/section-rss.jsp?section=3`, - Every: 2 * time.Hour, - }, - { - Name: "LOR Polls", - URL: `https://www.linux.org.ru/section-rss.jsp?section=5`, - Every: 2 * time.Hour, - }, - { - Name: "OpenNET", - URL: `http://www.opennet.ru/opennews/opennews_all_noadv.rss`, - Every: 4 * time.Hour, - }, - { - Name: "Undeadly", - URL: `http://undeadly.org/cgi?action=rss`, - Every: 2 * time.Hour, - }, - { - Name: "Kernel", - URL: `https://www.kernel.org/feeds/kdist.xml`, - Every: 6 * time.Hour, - }, - { - Name: "Ted Unangst", - URL: `http://www.tedunangst.com/flak/rss`, - Every: 6 * time.Hour, - }, - { - Name: "Calomel", - URL: `https://calomel.org/calomel_rss.xml`, - Every: 6 * time.Hour, - }, - { - Name: "Golang News", - URL: `https://golangnews.com/index.xml`, - Every: 6 * time.Hour, - }, - { - Name: "Golang Weekly", - URL: `http://golangweekly.com/rss/1fg21ahk`, - Every: 6 * time.Hour, - }, -} - type News struct { Feed rss.Item @@ -88,7 +30,7 @@ func (n News) String() string { return s } -func (f Feed) Watch(news chan News) { +func (f Feed) watch(news chan News) { ticker := time.NewTicker(f.Every) defer ticker.Stop() for t := range ticker.C { @@ -106,10 +48,10 @@ func (f Feed) Watch(news chan News) { } } -func watchNews(msg chan string) { +func Watch(msg chan string, feeds []Feed) { news := make(chan News) - for _, feed := range Feeds { - go feed.Watch(news) + for _, feed := range feeds { + go feed.watch(news) } for n := range news { msg <- fmt.Sprint(n) -- cgit v1.2.3