Skip to content

Commit ce7c5da

Browse files
committed
Change datastore quickstart sample to create a task.
1 parent 549d063 commit ce7c5da

File tree

1 file changed

+11
-9
lines changed
  • datastore/datastore_quickstart

1 file changed

+11
-9
lines changed

datastore/datastore_quickstart/main.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
type Task struct {
19-
Value string
19+
Description string
2020
}
2121

2222
func 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

Comments
 (0)