cpolis/cmd/ui/rss.go

26 lines
529 B
Go
Raw Normal View History

package ui
import (
"html/template"
"log"
"net/http"
"streifling.com/jason/cpolis/cmd/data"
)
2024-03-01 21:01:38 +01:00
func ShowRSS(f *data.Feed) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
feed := f.Get()
rss, err := feed.ToRss()
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
2024-03-02 09:09:55 +01:00
files := []string{"web/templates/index.html", "web/templates/feed.rss"}
tmpl, err := template.ParseFiles(files...)
template.Must(tmpl, err).Execute(w, rss)
}
}