Commit f642f621e11a2f33434861697d51cd3fc1938974
0 parents
Exists in
master
and in
1 other branch
Initial commit. Basic key/value pairs.
Showing 2 changed files with 60 additions and 0 deletions Side-by-side Diff
app.yaml
View file @
f642f62
src/main.go
View file @
f642f62
... | ... | @@ -0,0 +1,52 @@ |
1 | +package webhash | |
2 | + | |
3 | +import ( | |
4 | + "html/template" | |
5 | + "net/http" | |
6 | + | |
7 | + "appengine" | |
8 | + "appengine/datastore" | |
9 | + // "appengine/user" | |
10 | +) | |
11 | + | |
12 | +func init() { | |
13 | + http.HandleFunc("/", handlerRoot) | |
14 | +} | |
15 | + | |
16 | +type User struct { | |
17 | + UserID string | |
18 | + Value string | |
19 | +} | |
20 | + | |
21 | +func handlerRoot(w http.ResponseWriter, r *http.Request) { | |
22 | + c := appengine.NewContext(r) | |
23 | + u := User{ | |
24 | + UserID: r.FormValue("userid"), | |
25 | + Value: r.FormValue("value"), | |
26 | + } | |
27 | + k := datastore.NewKey(c, "User", u.UserID, 0, nil) | |
28 | + | |
29 | + if u.Value == "" { | |
30 | + datastore.Get(c, k, &u) | |
31 | + } else { | |
32 | + datastore.Put(c, k, &u) | |
33 | + } | |
34 | + | |
35 | + rootTemplate.Execute(w, u.Value) | |
36 | + | |
37 | +} | |
38 | + | |
39 | +var rootTemplate = template.Must(template.New("root").Parse(rootTemplateHTML)) | |
40 | + | |
41 | +const rootTemplateHTML = ` | |
42 | +<!DOCTYPE HTML> | |
43 | +<html> | |
44 | + <head> | |
45 | + <title>WebHash Go</title> | |
46 | + <meta charset="utf-8"> | |
47 | + </head> | |
48 | + <body> | |
49 | + {{.}} | |
50 | + </body> | |
51 | +</html> | |
52 | +` |