llist/genrss.go -rw-r--r-- 880 bytes 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
package main

import (
	"net/http"
	"text/template"
)

const RSStmpl = `<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"><channel>
<title>Philip's link list</title>
<description>A collection of cyperspace links. </description>
<link>http://phi.k.vu/llist.cgi</link>
{{ range . }}
<item>
  <title>{{ .Title }}</title>
  <link>{{ .Url }}</link>
  <pubDate>{{ .Posted.Format "Mon Jan _2 15:04:05 2006"  }}</pubDate>
</item>
{{ end }}
</channel></rss>`

var RSS = template.Must(template.New("").Parse(RSStmpl))

func genrss(rw http.ResponseWriter, req *http.Request) {
	ent, err := queryLinks(1, "")
	if err != nil {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
		return
	}

	rw.Header().Set("Content-Type:", "text/xml; charset=UTF-8")
	err = RSS.Execute(rw, ent)
	if err != nil {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
		return
	}
}