Last active
September 20, 2015 07:26
-
-
Save IndianGuru/4071034854c4d69b2386 to your computer and use it in GitHub Desktop.
The Add service
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) | |
| } | |
| // Add creates a new quote given the fields in AddRequest, stores it in the | |
| // datastore, and returns it. | |
| func (QuotesAPI) Add(c context.Context, r *AddRequest) (*Quote, error) { | |
| // 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. | |
| k := datastore.NewIncompleteKey(c, "Quote", quoteKey(c)) | |
| t := &Quote{Author: r.Author, Message: r.Message} | |
| k, err := datastore.Put(c, k, t) | |
| if err != nil { | |
| return nil, err | |
| } | |
| t.UID = k | |
| return t, nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment