cpolis/cmd/ui/rss.go

29 lines
641 B
Go

package ui
import (
"html/template"
"log"
"net/http"
"git.streifling.com/jason/rss"
"streifling.com/jason/cpolis/cmd/data"
)
func ShowRSS(c *data.Channel) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
channel := c.Get()
feed := rss.NewFeed()
feed.Channels = append(feed.Channels, &channel)
rss, err := feed.ToXML()
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
files := []string{"web/templates/index.html", "web/templates/feed.rss"}
tmpl, err := template.ParseFiles(files...)
template.Must(tmpl, err).Execute(w, rss)
}
}