Skip to content

Commit 66b9c49

Browse files
mafredrigaryburd
authored andcommitted
Move context to first parameter in DialContext
Follows best practice and pkg/context documentation: > The Context should be the first parameter, typically named ctx
1 parent a9dd6e8 commit 66b9c49

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ type Dialer struct {
103103

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

109109
var errMalformedURL = errors.New("malformed ws or wss URL")
@@ -146,7 +146,7 @@ var nilDialer = *DefaultDialer
146146
// non-nil *http.Response so that callers can handle redirects, authentication,
147147
// etcetera. The response body may not contain the entire response and does not
148148
// need to be closed by the application.
149-
func (d *Dialer) DialContext(urlStr string, requestHeader http.Header, ctx context.Context) (*Conn, *http.Response, error) {
149+
func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) {
150150
if d == nil {
151151
d = &nilDialer
152152
}

client_server_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func TestHandshakeTimeoutInContext(t *testing.T) {
424424

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

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

783-
ws, _, err := d.DialContext(s.URL, nil, ctx)
783+
ws, _, err := d.DialContext(ctx, s.URL, nil)
784784
if err != nil {
785785
t.Fatalf("Dial: %v", err)
786786
}

0 commit comments

Comments
 (0)