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

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

func genuser(rw http.ResponseWriter, req *http.Request) {
	loadUsers()
	name := req.URL.Query().Get("id")
	lpage, err := strconv.Atoi(req.URL.Query().Get("lp"))
	if err != nil {
		lpage = 1
	}
	cpage, err := strconv.Atoi(req.URL.Query().Get("cp"))
	if err != nil {
		cpage = 1
	}
	links, comms, err := queryUser(name, lpage, cpage)

	if err := tmpl.ExecuteTemplate(rw, "user.gtml", struct {
		Name  string
		Usr   User
		Links []Link
		Lpage int
		Lnext bool
		Comms []Comment
		Cpage int
		Cnext bool
	}{name, users[name],
		links, lpage, len(links) > UITEMS,
		comms, cpage, len(comms) > UITEMS}); err != nil {
		log.Fatal(err)
	}
}