-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeed.go
37 lines (33 loc) · 887 Bytes
/
feed.go
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
package main
import (
"github.com/nvcnvn/feeds"
"time"
)
func Feed(c *controller) {
feed := &feeds.Feed{
Title: "Demo RSS/Atom Golang MongoDB OpenSihft",
Link: &feeds.Link{Href: "http://gotest-openvn.rhcloud.com/feed"},
Description: "Khong biet noi gi",
Author: &feeds.Author{"Cao Nguyen", "nguyen@open-vn.org"},
Created: time.Now(),
Copyright: "copyright © no one",
}
thrs, err := c.db.NewestThreads(10)
if err != nil {
return
}
items := make([]*feeds.Item, len(thrs), len(thrs))
for i := 0; i < len(thrs); i++ {
items[i] = &thrs[i].Item
items[i].Link.Href = "http://gotest-openvn.rhcloud.com" + items[i].Link.Href
}
feed.Items = items
var xml string
if c.Get("format", false) == "rss" {
xml, _ = feed.ToRss()
} else {
xml, _ = feed.ToAtom()
}
c.Response.Header().Set("Content-type", "application/xml")
c.Print(xml)
}