cmd/server/genrss.go (view raw)
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 38 39 40 |
package main
import (
"fmt"
"os"
"text/template"
)
type (
rssItem struct {
Title string
Link string
}
)
func genRSS(blogDataSlice []blogData) {
var rssItemSlice []rssItem
for _, post := range blogDataSlice {
rssItemSlice = append(rssItemSlice, rssItem{
Title: post.Title,
Link: post.URL,
})
}
tpl, err := template.ParseFiles("templates/rss.xml.gotmpl")
if err != nil {
fmt.Printf("ERROR creating template: %s\n", err)
}
f, err := os.Create("html/en/blog/rss.xml.html")
if err != nil {
fmt.Printf("ERROR creating xml: %s\n", err)
panic(1)
}
err = tpl.ExecuteTemplate(f, "rss.xml.gotmpl", rssItemSlice)
if err != nil {
fmt.Printf("ERROR executing template: %s\n", err)
}
}
|