From e6249e5059a7a003fd7c1db259e50826d43e8db3 Mon Sep 17 00:00:00 2001 From: Iheanyi Ekechukwu Date: Tue, 8 May 2018 16:24:29 -0400 Subject: [PATCH] Remove support for Go 1.6 (#166) * Move DoRequest* to godo package with stdlib context * Use stdlib context package in place of godo context. * Remove Go 1.6 from TravisCI configuration. * Use stdlib context in util and tests instead of godo context. * Add in Go 1.8, 1.9, and 1.10 to TravisCI configuration. * Put 1.10 in quotes. --- .travis.yml | 4 +- account.go | 3 +- action.go | 3 +- certificates.go | 3 +- context/context.go | 98 ------------------------------------- context/context_go17.go | 39 --------------- context/context_pre_go17.go | 41 ---------------- domains.go | 3 +- droplet_actions.go | 3 +- droplets.go | 3 +- firewalls.go | 3 +- floating_ips.go | 3 +- floating_ips_actions.go | 3 +- godo.go | 20 ++++++-- godo_test.go | 3 +- image_actions.go | 3 +- images.go | 3 +- keys.go | 3 +- links.go | 3 +- load_balancers.go | 3 +- regions.go | 3 +- sizes.go | 3 +- snapshots.go | 3 +- snapshots_test.go | 3 +- storage.go | 6 +-- storage_actions.go | 3 +- tags.go | 3 +- util/droplet.go | 2 +- util/droplet_test.go | 3 +- 29 files changed, 46 insertions(+), 230 deletions(-) delete mode 100644 context/context.go delete mode 100644 context/context_go17.go delete mode 100644 context/context_pre_go17.go diff --git a/.travis.yml b/.travis.yml index 7b27b09a..5bbdb40f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: go go: - - 1.6.3 - 1.7 + - 1.8 + - 1.9 + - "1.10" - tip diff --git a/account.go b/account.go index db25f100..8dce7098 100644 --- a/account.go +++ b/account.go @@ -1,9 +1,8 @@ package godo import ( + "context" "net/http" - - "github.com/digitalocean/godo/context" ) // AccountService is an interface for interfacing with the Account diff --git a/action.go b/action.go index 3990f564..67ef3ab8 100644 --- a/action.go +++ b/action.go @@ -1,10 +1,9 @@ package godo import ( + "context" "fmt" "net/http" - - "github.com/digitalocean/godo/context" ) const ( diff --git a/certificates.go b/certificates.go index ca95cee7..2414df4f 100644 --- a/certificates.go +++ b/certificates.go @@ -1,10 +1,9 @@ package godo import ( + "context" "net/http" "path" - - "github.com/digitalocean/godo/context" ) const certificatesBasePath = "/v2/certificates" diff --git a/context/context.go b/context/context.go deleted file mode 100644 index fe49b8df..00000000 --- a/context/context.go +++ /dev/null @@ -1,98 +0,0 @@ -package context - -import "time" - -// A Context carries a deadline, a cancelation signal, and other values across -// API boundaries. -// -// Context's methods may be called by multiple goroutines simultaneously. -type Context interface { - // Deadline returns the time when work done on behalf of this context - // should be canceled. Deadline returns ok==false when no deadline is - // set. Successive calls to Deadline return the same results. - Deadline() (deadline time.Time, ok bool) - - // Done returns a channel that's closed when work done on behalf of this - // context should be canceled. Done may return nil if this context can - // never be canceled. Successive calls to Done return the same value. - // - // WithCancel arranges for Done to be closed when cancel is called; - // WithDeadline arranges for Done to be closed when the deadline - // expires; WithTimeout arranges for Done to be closed when the timeout - // elapses. - // - // Done is provided for use in select statements:s - // - // // Stream generates values with DoSomething and sends them to out - // // until DoSomething returns an error or ctx.Done is closed. - // func Stream(ctx context.Context, out chan<- Value) error { - // for { - // v, err := DoSomething(ctx) - // if err != nil { - // return err - // } - // select { - // case <-ctx.Done(): - // return ctx.Err() - // case out <- v: - // } - // } - // } - // - // See http://blog.golang.org/pipelines for more examples of how to use - // a Done channel for cancelation. - Done() <-chan struct{} - - // Err returns a non-nil error value after Done is closed. Err returns - // Canceled if the context was canceled or DeadlineExceeded if the - // context's deadline passed. No other values for Err are defined. - // After Done is closed, successive calls to Err return the same value. - Err() error - - // Value returns the value associated with this context for key, or nil - // if no value is associated with key. Successive calls to Value with - // the same key returns the same result. - // - // Use context values only for request-scoped data that transits - // processes and API boundaries, not for passing optional parameters to - // functions. - // - // A key identifies a specific value in a Context. Functions that wish - // to store values in Context typically allocate a key in a global - // variable then use that key as the argument to context.WithValue and - // Context.Value. A key can be any type that supports equality; - // packages should define keys as an unexported type to avoid - // collisions. - // - // Packages that define a Context key should provide type-safe accessors - // for the values stores using that key: - // - // // Package user defines a User type that's stored in Contexts. - // package user - // - // import "golang.org/x/net/context" - // - // // User is the type of value stored in the Contexts. - // type User struct {...} - // - // // key is an unexported type for keys defined in this package. - // // This prevents collisions with keys defined in other packages. - // type key int - // - // // userKey is the key for user.User values in Contexts. It is - // // unexported; clients use user.NewContext and user.FromContext - // // instead of using this key directly. - // var userKey key = 0 - // - // // NewContext returns a new Context that carries value u. - // func NewContext(ctx context.Context, u *User) context.Context { - // return context.WithValue(ctx, userKey, u) - // } - // - // // FromContext returns the User value stored in ctx, if any. - // func FromContext(ctx context.Context) (*User, bool) { - // u, ok := ctx.Value(userKey).(*User) - // return u, ok - // } - Value(key interface{}) interface{} -} diff --git a/context/context_go17.go b/context/context_go17.go deleted file mode 100644 index d5359ded..00000000 --- a/context/context_go17.go +++ /dev/null @@ -1,39 +0,0 @@ -// +build go1.7 - -package context - -import ( - "context" - "net/http" -) - -// DoRequest submits an HTTP request. -func DoRequest(ctx Context, req *http.Request) (*http.Response, error) { - return DoRequestWithClient(ctx, http.DefaultClient, req) -} - -// DoRequestWithClient submits an HTTP request using the specified client. -func DoRequestWithClient( - ctx Context, - client *http.Client, - req *http.Request) (*http.Response, error) { - req = req.WithContext(ctx) - return client.Do(req) -} - -// TODO returns a non-nil, empty Context. Code should use context.TODO when -// it's unclear which Context to use or it is not yet available (because the -// surrounding function has not yet been extended to accept a Context -// parameter). TODO is recognized by static analysis tools that determine -// whether Contexts are propagated correctly in a program. -func TODO() Context { - return context.TODO() -} - -// Background returns a non-nil, empty Context. It is never canceled, has no -// values, and has no deadline. It is typically used by the main function, -// initialization, and tests, and as the top-level Context for incoming -// requests. -func Background() Context { - return context.Background() -} diff --git a/context/context_pre_go17.go b/context/context_pre_go17.go deleted file mode 100644 index e30adb0c..00000000 --- a/context/context_pre_go17.go +++ /dev/null @@ -1,41 +0,0 @@ -// +build !go1.7 - -package context - -import ( - "net/http" - - "golang.org/x/net/context" - "golang.org/x/net/context/ctxhttp" -) - -// DoRequest submits an HTTP request. -func DoRequest(ctx Context, req *http.Request) (*http.Response, error) { - return DoRequestWithClient(ctx, http.DefaultClient, req) -} - -// DoRequestWithClient submits an HTTP request using the specified client. -func DoRequestWithClient( - ctx Context, - client *http.Client, - req *http.Request) (*http.Response, error) { - - return ctxhttp.Do(ctx, client, req) -} - -// TODO returns a non-nil, empty Context. Code should use context.TODO when -// it's unclear which Context to use or it is not yet available (because the -// surrounding function has not yet been extended to accept a Context -// parameter). TODO is recognized by static analysis tools that determine -// whether Contexts are propagated correctly in a program. -func TODO() Context { - return context.TODO() -} - -// Background returns a non-nil, empty Context. It is never canceled, has no -// values, and has no deadline. It is typically used by the main function, -// initialization, and tests, and as the top-level Context for incoming -// requests. -func Background() Context { - return context.Background() -} diff --git a/domains.go b/domains.go index f52d0524..63bc9046 100644 --- a/domains.go +++ b/domains.go @@ -1,10 +1,9 @@ package godo import ( + "context" "fmt" "net/http" - - "github.com/digitalocean/godo/context" ) const domainsBasePath = "v2/domains" diff --git a/droplet_actions.go b/droplet_actions.go index a40d1970..3d31ae27 100644 --- a/droplet_actions.go +++ b/droplet_actions.go @@ -1,11 +1,10 @@ package godo import ( + "context" "fmt" "net/http" "net/url" - - "github.com/digitalocean/godo/context" ) // ActionRequest reprents DigitalOcean Action Request diff --git a/droplets.go b/droplets.go index 5ec898b2..a3650edf 100644 --- a/droplets.go +++ b/droplets.go @@ -1,12 +1,11 @@ package godo import ( + "context" "encoding/json" "errors" "fmt" "net/http" - - "github.com/digitalocean/godo/context" ) const dropletBasePath = "v2/droplets" diff --git a/firewalls.go b/firewalls.go index afc0af32..f34774bb 100644 --- a/firewalls.go +++ b/firewalls.go @@ -1,11 +1,10 @@ package godo import ( + "context" "net/http" "path" "strconv" - - "github.com/digitalocean/godo/context" ) const firewallsBasePath = "/v2/firewalls" diff --git a/floating_ips.go b/floating_ips.go index a9187dca..deea3a13 100644 --- a/floating_ips.go +++ b/floating_ips.go @@ -1,10 +1,9 @@ package godo import ( + "context" "fmt" "net/http" - - "github.com/digitalocean/godo/context" ) const floatingBasePath = "v2/floating_ips" diff --git a/floating_ips_actions.go b/floating_ips_actions.go index 2fd2393c..74ad279f 100644 --- a/floating_ips_actions.go +++ b/floating_ips_actions.go @@ -1,10 +1,9 @@ package godo import ( + "context" "fmt" "net/http" - - "github.com/digitalocean/godo/context" ) // FloatingIPActionsService is an interface for interfacing with the diff --git a/godo.go b/godo.go index 897ce0e6..dac2eeaa 100644 --- a/godo.go +++ b/godo.go @@ -2,6 +2,7 @@ package godo import ( "bytes" + "context" "encoding/json" "fmt" "io" @@ -14,8 +15,6 @@ import ( "github.com/google/go-querystring/query" headerLink "github.com/tent/http-link-go" - - "github.com/digitalocean/godo/context" ) const ( @@ -296,7 +295,7 @@ func (r *Response) populateRate() { // pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, // the raw response will be written to v, without attempting to decode it. func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error) { - resp, err := context.DoRequestWithClient(ctx, c.client, req) + resp, err := DoRequestWithClient(ctx, c.client, req) if err != nil { return nil, err } @@ -334,6 +333,21 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res return response, err } + +// DoRequest submits an HTTP request. +func DoRequest(ctx context.Context, req *http.Request) (*http.Response, error) { + return DoRequestWithClient(ctx, http.DefaultClient, req) +} + +// DoRequestWithClient submits an HTTP request using the specified client. +func DoRequestWithClient( + ctx context.Context, + client *http.Client, + req *http.Request) (*http.Response, error) { + req = req.WithContext(ctx) + return client.Do(req) +} + func (r *ErrorResponse) Error() string { if r.RequestID != "" { return fmt.Sprintf("%v %v: %d (request %q) %v", diff --git a/godo_test.go b/godo_test.go index b4a04d03..e075293e 100644 --- a/godo_test.go +++ b/godo_test.go @@ -1,6 +1,7 @@ package godo import ( + "context" "fmt" "io/ioutil" "net/http" @@ -11,8 +12,6 @@ import ( "strings" "testing" "time" - - "github.com/digitalocean/godo/context" ) var ( diff --git a/image_actions.go b/image_actions.go index 1e9fa312..976f7c68 100644 --- a/image_actions.go +++ b/image_actions.go @@ -1,10 +1,9 @@ package godo import ( + "context" "fmt" "net/http" - - "github.com/digitalocean/godo/context" ) // ImageActionsService is an interface for interfacing with the image actions diff --git a/images.go b/images.go index af989f41..c1fd0128 100644 --- a/images.go +++ b/images.go @@ -1,10 +1,9 @@ package godo import ( + "context" "fmt" "net/http" - - "github.com/digitalocean/godo/context" ) const imageBasePath = "v2/images" diff --git a/keys.go b/keys.go index 2ffdd6cc..9695c21f 100644 --- a/keys.go +++ b/keys.go @@ -1,10 +1,9 @@ package godo import ( + "context" "fmt" "net/http" - - "github.com/digitalocean/godo/context" ) const keysBasePath = "v2/account/keys" diff --git a/links.go b/links.go index 0c611021..20984417 100644 --- a/links.go +++ b/links.go @@ -1,10 +1,9 @@ package godo import ( + "context" "net/url" "strconv" - - "github.com/digitalocean/godo/context" ) // Links manages links that are returned along with a List diff --git a/load_balancers.go b/load_balancers.go index 81c0bdfb..de19fe7f 100644 --- a/load_balancers.go +++ b/load_balancers.go @@ -1,10 +1,9 @@ package godo import ( + "context" "fmt" "net/http" - - "github.com/digitalocean/godo/context" ) const loadBalancersBasePath = "/v2/load_balancers" diff --git a/regions.go b/regions.go index de7603fd..409959d9 100644 --- a/regions.go +++ b/regions.go @@ -1,9 +1,8 @@ package godo import ( + "context" "net/http" - - "github.com/digitalocean/godo/context" ) // RegionsService is an interface for interfacing with the regions diff --git a/sizes.go b/sizes.go index f0c5a051..da8207c0 100644 --- a/sizes.go +++ b/sizes.go @@ -1,9 +1,8 @@ package godo import ( + "context" "net/http" - - "github.com/digitalocean/godo/context" ) // SizesService is an interface for interfacing with the size diff --git a/snapshots.go b/snapshots.go index 8a42aed3..181188db 100644 --- a/snapshots.go +++ b/snapshots.go @@ -1,10 +1,9 @@ package godo import ( + "context" "fmt" "net/http" - - "github.com/digitalocean/godo/context" ) const snapshotBasePath = "v2/snapshots" diff --git a/snapshots_test.go b/snapshots_test.go index 61e70d79..728be7dc 100644 --- a/snapshots_test.go +++ b/snapshots_test.go @@ -1,12 +1,11 @@ package godo import ( + "context" "fmt" "net/http" "reflect" "testing" - - "github.com/digitalocean/godo/context" ) func TestSnapshots_List(t *testing.T) { diff --git a/storage.go b/storage.go index 8127acc5..92fd3a0d 100644 --- a/storage.go +++ b/storage.go @@ -1,12 +1,10 @@ package godo import ( + "context" "fmt" - "time" - "net/http" - - "github.com/digitalocean/godo/context" + "time" ) const ( diff --git a/storage_actions.go b/storage_actions.go index fe916ac8..94889756 100644 --- a/storage_actions.go +++ b/storage_actions.go @@ -1,10 +1,9 @@ package godo import ( + "context" "fmt" "net/http" - - "github.com/digitalocean/godo/context" ) // StorageActionsService is an interface for interfacing with the diff --git a/tags.go b/tags.go index 6427488d..124140dc 100644 --- a/tags.go +++ b/tags.go @@ -1,10 +1,9 @@ package godo import ( + "context" "fmt" "net/http" - - "github.com/digitalocean/godo/context" ) const tagsBasePath = "v2/tags" diff --git a/util/droplet.go b/util/droplet.go index 62f8c0e0..e7c48e2b 100644 --- a/util/droplet.go +++ b/util/droplet.go @@ -1,11 +1,11 @@ package util import ( + "context" "fmt" "time" "github.com/digitalocean/godo" - "github.com/digitalocean/godo/context" ) const ( diff --git a/util/droplet_test.go b/util/droplet_test.go index 9dad90a4..823d3121 100644 --- a/util/droplet_test.go +++ b/util/droplet_test.go @@ -1,10 +1,11 @@ package util import ( + "context" + "golang.org/x/oauth2" "github.com/digitalocean/godo" - "github.com/digitalocean/godo/context" ) func ExampleWaitForActive() {