Last active
September 21, 2015 03:53
-
-
Save IndianGuru/5e46157e92e7c71150c9 to your computer and use it in GitHub Desktop.
Modified quote() in quote.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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