From d208c5132e6ba3d2d8dc714582d8b8859409d14b Mon Sep 17 00:00:00 2001 From: Ben Tranter Date: Fri, 28 Feb 2020 11:36:05 -0500 Subject: [PATCH 1/3] Update README to use NewFromToken --- README.md | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index b52a5439..bf88f207 100644 --- a/README.md +++ b/README.md @@ -43,33 +43,11 @@ 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 := NewFromToken("my-digitalocean-api-token") } ``` From d3c5fa5e6c87cb4d0a7a9a07addf11e7e09d2c06 Mon Sep 17 00:00:00 2001 From: Ben Tranter Date: Mon, 16 Mar 2020 10:58:07 -0400 Subject: [PATCH 2/3] Prefix package name to example Co-Authored-By: Andrew Starr-Bochicchio --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf88f207..e1019f15 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ import ( ) func main() { - client := NewFromToken("my-digitalocean-api-token") + client := godo.NewFromToken("my-digitalocean-api-token") } ``` From e1575cffe026cd6733e96b510efce535e91c3d8f Mon Sep 17 00:00:00 2001 From: Ben Tranter Date: Mon, 16 Mar 2020 11:30:42 -0400 Subject: [PATCH 3/3] Expand documentation for NewClient Also adds a reference to the godoc for the (now old) NewClient method. --- README.md | 2 ++ godo.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1019f15..cadeb69e 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ func main() { } ``` +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 diff --git a/godo.go b/godo.go index 58a1b22a..f225e299 100644 --- a/godo.go +++ b/godo.go @@ -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