Skip to content

Commit

Permalink
Move context to first parameter in DialContext
Browse files Browse the repository at this point in the history
Follows best practice and pkg/context documentation:

> The Context should be the first parameter, typically named ctx
  • Loading branch information
mafredri authored and garyburd committed Aug 25, 2018
1 parent a9dd6e8 commit 66b9c49
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type Dialer struct {

// Dial creates a new client connection by calling DialContext with a background context.
func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) {
return d.DialContext(urlStr, requestHeader, context.Background())
return d.DialContext(context.Background(), urlStr, requestHeader)
}

var errMalformedURL = errors.New("malformed ws or wss URL")
Expand Down Expand Up @@ -146,7 +146,7 @@ var nilDialer = *DefaultDialer
// non-nil *http.Response so that callers can handle redirects, authentication,
// etcetera. The response body may not contain the entire response and does not
// need to be closed by the application.
func (d *Dialer) DialContext(urlStr string, requestHeader http.Header, ctx context.Context) (*Conn, *http.Response, error) {
func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) {
if d == nil {
d = &nilDialer
}
Expand Down
6 changes: 3 additions & 3 deletions client_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func TestHandshakeTimeoutInContext(t *testing.T) {

ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(30*time.Second))
defer cancel()
ws, _, err := d.DialContext(s.URL, nil, ctx)
ws, _, err := d.DialContext(ctx, s.URL, nil)
if err != nil {
t.Fatal("Dial:", err)
}
Expand Down Expand Up @@ -730,7 +730,7 @@ func TestTracingDialWithContext(t *testing.T) {
d := cstDialer
d.TLSClientConfig = &tls.Config{RootCAs: certs}

ws, _, err := d.DialContext(s.URL, nil, ctx)
ws, _, err := d.DialContext(ctx, s.URL, nil)
if err != nil {
t.Fatalf("Dial: %v", err)
}
Expand Down Expand Up @@ -780,7 +780,7 @@ func TestEmptyTracingDialWithContext(t *testing.T) {
d := cstDialer
d.TLSClientConfig = &tls.Config{RootCAs: certs}

ws, _, err := d.DialContext(s.URL, nil, ctx)
ws, _, err := d.DialContext(ctx, s.URL, nil)
if err != nil {
t.Fatalf("Dial: %v", err)
}
Expand Down

0 comments on commit 66b9c49

Please sign in to comment.