-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.go
56 lines (52 loc) · 1.42 KB
/
controller.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package articles
import (
"../../../../webtool"
"../../libs"
"net/http"
"strconv"
)
func TopPage(transaction TransactionInterface) (message string, err webtool.ActionError) {
//fmt.Fprintf(w, "Accept, %q\n", html.EscapeString(r.URL.Path))
data := make(map[string]string)
data["title"] = "タイトル"
data["message"] = "Hello, world."
view := libs.Viewer("templates/articles/top.html")
if view != nil {
view(transaction.Writer(), data)
} else {
err = webtool.NewActionError("404", "View Not Found")
}
message = "TopPage:" + r.URL.Path
return
}
func ArticlePage(transaction TransactionInterface) (message string, err webtool.ActionError) {
params := transaction.DefaultParams()
message = "TopPage:" + r.URL.Path
data := make(map[string]interface{})
data["title"] = "タイトル"
_, ok := params["id"]
if ok {
id, e := strconv.ParseInt(params["id"], 10, 0)
if e != nil {
err = webtool.NewActionError("404", "id mismatch")
return
}
data["id"] = id
article, e := Get(id)
if e != nil {
err = webtool.NewActionError("404", "article not found")
return
}
data["article"] = article
} else {
err = webtool.NewActionError("404", "article not found")
return
}
view := libs.Viewer("templates/articles/article.html")
if view != nil {
view(transaction.Writer(), data)
} else {
err = webtool.NewActionError("404", "view not found")
}
return
}