Skip to content

Commit

Permalink
Update README with context.Context usage. (digitalocean#127)
Browse files Browse the repository at this point in the history
* Update README with context.Context usage.

* s/Background/TODO/
  • Loading branch information
andrewsomething authored Feb 24, 2017
1 parent 342aee3 commit 65af727
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ createRequest := &godo.DropletCreateRequest{
},
}

newDroplet, _, err := client.Droplets.Create(createRequest)
ctx := context.TODO()

newDroplet, _, err := client.Droplets.Create(ctx, createRequest)

if err != nil {
fmt.Printf("Something bad happened: %s\n\n", err)
Expand All @@ -78,14 +80,14 @@ if err != nil {
If a list of items is paginated by the API, you must request pages individually. For example, to fetch all Droplets:

```go
func DropletList(client *godo.Client) ([]godo.Droplet, error) {
func DropletList(ctx context.Context, client *godo.Client) ([]godo.Droplet, error) {
// create a list to hold our droplets
list := []godo.Droplet{}

// create options. initially, these will be blank
opt := &godo.ListOptions{}
for {
droplets, resp, err := client.Droplets.List(opt)
droplets, resp, err := client.Droplets.List(ctx, opt)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 65af727

Please sign in to comment.