@@ -16,7 +16,7 @@ import (
1616)
1717
1818type Task struct {
19- Value string
19+ Description string
2020}
2121
2222func main () {
@@ -31,21 +31,23 @@ func main() {
3131 log .Fatalf ("Failed to create client: %v" , err )
3232 }
3333
34- // The kind of the entity to retrieve
34+ // The kind for the new entity
3535 kind := "Task"
36- // The name/ID of the entity to retrieve
36+ // The name/ID for the new entity
3737 name := "sampletask1"
38- // The Datastore key for the entity
39- key := datastore .NewKey (ctx , kind , name , 0 , nil )
38+ // The Cloud Datastore key for the new entity
39+ taskKey := datastore .NewKey (ctx , kind , name , 0 , nil )
4040
41+ // Prepares the new entity
4142 task := new (Task )
43+ task .Description = "Buy milk"
4244
43- // Retrieves the task
44- if err := client .Get (ctx , key , task ); err != nil {
45- log .Fatalf ("Failed to get task: %v" , err )
45+ // Saves the entity
46+ if _ , err := client .Put (ctx , taskKey , task ); err != nil {
47+ log .Fatalf ("Failed to save task: %v" , err )
4648 }
4749
48- fmt .Printf ("Fetched task : %v" , key .String ())
50+ fmt .Printf ("Saved %v : %v" , taskKey .String (), task . Description )
4951}
5052
5153// [END datastore_quickstart]
0 commit comments