Skip to content

Commit

Permalink
Merge pull request #308 from bentranter/update-readme-with-new-client…
Browse files Browse the repository at this point in the history
…-init

Update README to use NewFromToken
  • Loading branch information
bentranter authored Mar 16, 2020
2 parents 37c786e + e1575cf commit 4acd72d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
28 changes: 4 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,16 @@ You can then use your token to create a new client:
package main

import (
"context"
"github.com/digitalocean/godo"
"golang.org/x/oauth2"
"github.com/digitalocean/godo"
)

const (
pat = "mytoken"
)

type TokenSource struct {
AccessToken string
}

func (t *TokenSource) Token() (*oauth2.Token, error) {
token := &oauth2.Token{
AccessToken: t.AccessToken,
}
return token, nil
}

func main() {
tokenSource := &TokenSource{
AccessToken: pat,
}

oauthClient := oauth2.NewClient(context.Background(), tokenSource)
client := godo.NewClient(oauthClient)
client := godo.NewFromToken("my-digitalocean-api-token")
}
```

If you need to provide a `context.Context` to your new client, you should use [`godo.NewClient`](https://godoc.org/github.com/digitalocean/godo#NewClient) to manually construct a client instead.

## Examples


Expand Down
7 changes: 6 additions & 1 deletion godo.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ func NewFromToken(token string) *Client {
return NewClient(oauth2.NewClient(ctx, ts))
}

// NewClient returns a new DigitalOcean API client.
// NewClient returns a new DigitalOcean API client, using the given
// http.Client to perform all requests.
//
// Users who wish to pass their own http.Client should use this method. If
// you're in need of further customization, the godo.New method allows more
// options, such as setting a custom URL or a custom user agent string.
func NewClient(httpClient *http.Client) *Client {
if httpClient == nil {
httpClient = http.DefaultClient
Expand Down

0 comments on commit 4acd72d

Please sign in to comment.