llist/genlist.go -rw-r--r-- 544 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
package main

import (
	"log"
	"net/http"
	"strconv"
)

func genlist(rw http.ResponseWriter, req *http.Request) {
	tag := req.URL.Query().Get("tag")
	page, err := strconv.Atoi(req.URL.Query().Get("p"))
	if err != nil {
		page = 1
	}

	ent, err := queryLinks(page, tag)
	if err != nil {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
		return
	}

	if err := tmpl.ExecuteTemplate(rw, "list.gtml", struct {
		Page int
		Data []Link
		Tag  string
		Next bool
	}{page, ent, tag, len(ent) > ITEMS}); err != nil {
		log.Fatal(err)
	}
}