-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (55 loc) · 1.67 KB
/
main.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
57
58
59
60
package main
import (
"appengine"
"appengine/datastore"
"github.com/gorilla/mux"
"github.com/russross/blackfriday"
"html/template"
"net/http"
)
func index(w http.ResponseWriter, r *http.Request) error {
data := map[string]interface{}{
"title": "top",
"description": "this is a starter app for GAE/Go",
"body": "hello world",
}
return executeTemplate(w, "index", 200, data)
}
func generalPage(w http.ResponseWriter, r *http.Request) error {
vars := mux.Vars(r)
keyName := vars["keyName"]
c := appengine.NewContext(r)
adminpage := &AdminPage{}
key := datastore.NewKey(c, "AdminPage", keyName, 0, nil)
err := datastore.Get(c, key, adminpage)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
bodyHTML := string(blackfriday.MarkdownBasic([]byte(adminpage.Content)))
data := map[string]interface{}{
"title": adminpage.Title,
"description": "this is a starter app for GAE/Go",
"update": adminpage.Update,
"body": bodyHTML,
}
return executeTemplate(w, "page", 200, data)
}
func articlePage(w http.ResponseWriter, r *http.Request) error {
vars := mux.Vars(r)
keyName := vars["keyName"]
data := map[string]interface{}{
"title": keyName,
"description": "this is a starter app for GAE/Go",
"body": keyName,
}
return executeTemplate(w, "page", 200, data)
}
func searchPage(w http.ResponseWriter, r *http.Request) error {
keyword := template.HTMLEscapeString(r.FormValue("keyword"))
data := map[string]interface{}{
"title": "Search Results of " + keyword,
"description": "Search Results of " + keyword,
"keyword": keyword,
}
return executeTemplate(w, "searchIndex", 200, data)
}