From f642f621e11a2f33434861697d51cd3fc1938974 Mon Sep 17 00:00:00 2001 From: David Shere Date: Fri, 4 Apr 2014 15:19:27 -0700 Subject: [PATCH] Initial commit. Basic key/value pairs. --- app.yaml | 8 ++++++++ src/main.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 app.yaml create mode 100644 src/main.go diff --git a/app.yaml b/app.yaml new file mode 100644 index 0000000..dc70839 --- /dev/null +++ b/app.yaml @@ -0,0 +1,8 @@ +application: webhash-go +version: 1 +runtime: go +api_version: go1 + +handlers: +- url: /.* + script: _go_app diff --git a/src/main.go b/src/main.go new file mode 100644 index 0000000..dbad0be --- /dev/null +++ b/src/main.go @@ -0,0 +1,52 @@ +package webhash + +import ( + "html/template" + "net/http" + + "appengine" + "appengine/datastore" + // "appengine/user" +) + +func init() { + http.HandleFunc("/", handlerRoot) +} + +type User struct { + UserID string + Value string +} + +func handlerRoot(w http.ResponseWriter, r *http.Request) { + c := appengine.NewContext(r) + u := User{ + UserID: r.FormValue("userid"), + Value: r.FormValue("value"), + } + k := datastore.NewKey(c, "User", u.UserID, 0, nil) + + if u.Value == "" { + datastore.Get(c, k, &u) + } else { + datastore.Put(c, k, &u) + } + + rootTemplate.Execute(w, u.Value) + +} + +var rootTemplate = template.Must(template.New("root").Parse(rootTemplateHTML)) + +const rootTemplateHTML = ` + + + + WebHash Go + + + + {{.}} + + +` -- 1.9.1