Skip to content

Instantly share code, notes, and snippets.

@IndianGuru
Last active September 21, 2015 03:53
Show Gist options
  • Select an option

  • Save IndianGuru/5e46157e92e7c71150c9 to your computer and use it in GitHub Desktop.

Select an option

Save IndianGuru/5e46157e92e7c71150c9 to your computer and use it in GitHub Desktop.
Modified quote() in quote.go
// quoteKey returns the key used for all quote entries.
func quoteKey(c context.Context) *datastore.Key {
return datastore.NewKey(c, "Quote", "default_quote", 0, nil)
}
func quote(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
q1 := Quote{
Author: r.FormValue("aut"),
Message: r.FormValue("quo"),
}
// We set the same parent key on every Quote entity to ensure each Quote
// is in the same entity group. Queries across the single entity group
// will be consistent.
key, err := datastore.Put(c, datastore.NewIncompleteKey(c, "Quote", quoteKey(c)), &q1)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var q2 Quote
err1 := datastore.Get(c, key, &q2)
if err1 != nil {
http.Error(w, err1.Error(), http.StatusInternalServerError)
return
}
err2 := quoteTemplate.Execute(w, q2.Message)
if err2 != nil {
http.Error(w, err2.Error(), http.StatusInternalServerError)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment