Skip to content

Commit

Permalink
Use context from standard library
Browse files Browse the repository at this point in the history
Bye bye Go 1.8.
  • Loading branch information
fsouza committed Feb 21, 2018
1 parent ca33ff2 commit c22d7da
Show file tree
Hide file tree
Showing 16 changed files with 18 additions and 30 deletions.
4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
name = "github.com/gorilla/mux"
version = "v1.5.0"

[[constraint]]
name = "golang.org/x/net"
branch = "master"

[[override]]
name = "github.com/Nvveen/Gotty"
source = "https://github.com/ijc25/Gotty.git"
Expand Down
9 changes: 4 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package docker
import (
"bufio"
"bytes"
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
Expand All @@ -34,8 +35,6 @@ import (
"github.com/docker/docker/pkg/homedir"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/stdcopy"
"golang.org/x/net/context"
"golang.org/x/net/context/ctxhttp"
)

const (
Expand Down Expand Up @@ -224,7 +223,7 @@ func NewVersionedClient(endpoint string, apiVersionString string) (*Client, erro

// WithTransport replaces underlying HTTP client of Docker Client by accepting
// a function that returns pointer to a transport object.
func (c *Client) WithTransport(trFunc func () *http.Transport) {
func (c *Client) WithTransport(trFunc func() *http.Transport) {
c.initializeNativeClient(trFunc)
}

Expand Down Expand Up @@ -475,7 +474,7 @@ func (c *Client) do(method, path string, doOptions doOptions) (*http.Response, e
ctx = context.Background()
}

resp, err := ctxhttp.Do(ctx, c.HTTPClient, req)
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
if err != nil {
if strings.Contains(err.Error(), "connection refused") {
return nil, ErrConnectionRefused
Expand Down Expand Up @@ -591,7 +590,7 @@ func (c *Client) stream(method, path string, streamOptions streamOptions) error
return chooseError(subCtx, err)
}
} else {
if resp, err = ctxhttp.Do(subCtx, c.HTTPClient, req); err != nil {
if resp, err = c.HTTPClient.Do(req.WithContext(subCtx)); err != nil {
if strings.Contains(err.Error(), "connection refused") {
return ErrConnectionRefused
}
Expand Down
3 changes: 1 addition & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package docker

import (
"bytes"
"context"
"fmt"
"io/ioutil"
"net/http"
Expand All @@ -18,8 +19,6 @@ import (
"strings"
"testing"
"time"

"golang.org/x/net/context"
)

func TestNewAPIClient(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package docker

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -16,7 +17,6 @@ import (
"time"

units "github.com/docker/go-units"
"golang.org/x/net/context"
)

// ErrContainerAlreadyExists is the error returned by CreateContainer when the
Expand Down
3 changes: 1 addition & 2 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package docker
import (
"bufio"
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -21,8 +22,6 @@ import (
"strings"
"testing"
"time"

"golang.org/x/net/context"
)

func TestStateString(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
package docker

import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"strconv"

"golang.org/x/net/context"
)

// Exec is the type representing a `docker exec` instance and containing the
Expand Down
3 changes: 1 addition & 2 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package docker

import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"errors"
Expand All @@ -16,8 +17,6 @@ import (
"os"
"strings"
"time"

"golang.org/x/net/context"
)

// APIImages represent an image returned in the ListImages call.
Expand Down
3 changes: 1 addition & 2 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
package docker

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"

"golang.org/x/net/context"
)

// ErrNetworkAlreadyExists is the error returned by CreateNetwork when the
Expand Down
3 changes: 1 addition & 2 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
package docker

import (
"context"
"encoding/json"
"io/ioutil"
"net/http"

"golang.org/x/net/context"
)

// PluginPrivilege represents a privilege for a plugin.
Expand Down
2 changes: 1 addition & 1 deletion swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
package docker

import (
"context"
"encoding/json"
"errors"
"net/http"
"net/url"
"strconv"

"github.com/docker/docker/api/types/swarm"
"golang.org/x/net/context"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion swarm_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
package docker

import (
"context"
"encoding/json"
"net/http"
"net/url"
"strconv"

"github.com/docker/docker/api/types/swarm"
"golang.org/x/net/context"
)

// NoSuchConfig is the error returned when a given config does not exist.
Expand Down
2 changes: 1 addition & 1 deletion swarm_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
package docker

import (
"context"
"encoding/json"
"net/http"
"net/url"
"strconv"

"github.com/docker/docker/api/types/swarm"
"golang.org/x/net/context"
)

// NoSuchNode is the error returned when a given node does not exist.
Expand Down
2 changes: 1 addition & 1 deletion swarm_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
package docker

import (
"context"
"encoding/json"
"net/http"
"net/url"
"strconv"

"github.com/docker/docker/api/types/swarm"
"golang.org/x/net/context"
)

// NoSuchSecret is the error returned when a given secret does not exist.
Expand Down
2 changes: 1 addition & 1 deletion swarm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package docker

import (
"context"
"encoding/json"
"io"
"net/http"
Expand All @@ -13,7 +14,6 @@ import (
"time"

"github.com/docker/docker/api/types/swarm"
"golang.org/x/net/context"
)

// NoSuchService is the error returned when a given service does not exist.
Expand Down
2 changes: 1 addition & 1 deletion swarm_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
package docker

import (
"context"
"encoding/json"
"net/http"

"github.com/docker/docker/api/types/swarm"
"golang.org/x/net/context"
)

// NoSuchTask is the error returned when a given task does not exist.
Expand Down
3 changes: 1 addition & 2 deletions volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
package docker

import (
"context"
"encoding/json"
"errors"
"net/http"

"golang.org/x/net/context"
)

var (
Expand Down

0 comments on commit c22d7da

Please sign in to comment.