Exemplo n.º 1
0
func apiFeedHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, xml.Header)
	enc := xml.NewEncoder(w)
	vars := mux.Vars(r)
	name := vars["name"]
	feed, _ := db.GetFeedByName(name)
	entries := structure.ExtractEntriesFromFeeds(feed)
	filter, _ := db.GetFilter()
	entries = structure.FilterEntries(entries, filter)
	atomfeed := atom.CreateAtomFeed(feed.Title, feed.Subtitle, feed.Name, feed.Title, feed.Twitter, feed.Updated)
	for _, entry := range entries {
		atomfeed.AddEntry(entry.Title, entry.Summary, entry.Content, entry.ID, entry.ID, entry.PermaLink, entry.Author, entry.Twitter, entry.Updated)
	}
	enc.Encode(atomfeed)
}
Exemplo n.º 2
0
func (c *Cache) Set(key string) {
	log.Printf("brooklet: Adding '%s' to cache\n", key)
	if key == "all" {
		c.SetAll()
		return
	}
	c.lock.Lock()
	defer c.lock.Unlock()
	feed, _ := db.GetFeedByName(key)
	entries := structure.ExtractEntriesFromFeeds(feed)
	filter, _ := db.GetFilter()
	entries = structure.FilterEntries(entries, filter)
	if len(entries) > 100 {
		entries = entries[:100]
	}
	var d Data
	d.timestamp = time.Now()
	d.Title = feed.Title
	d.Entries = entries
	c.data[key] = d
}