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 Inline Diff
app.yaml
View file @
f642f62
File was created | 1 | application: webhash-go | ||
2 | version: 1 | |||
3 | runtime: go | |||
4 | api_version: go1 | |||
5 | ||||
6 | handlers: | |||
7 | - url: /.* |
src/main.go
View file @
f642f62
File was created | 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> |