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 = ` + + +
+