Skip to content

Commit 10339dd

Browse files
author
dvilaverde
committed
Allow connect with context in order to provide configurable connect timeouts
1 parent 5427a8d commit 10339dd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

client/conn.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,19 @@ func Connect(addr string, user string, password string, dbName string, options .
6969
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
7070
defer cancel()
7171

72-
dialer := &net.Dialer{}
72+
return ConnectWithContext(ctx, addr, user, password, dbName, options...)
73+
}
7374

75+
// ConnectWithContext to a MySQL addr using the provided context.
76+
func ConnectWithContext(ctx context.Context, addr string, user string, password string, dbName string, options ...func(*Conn)) (*Conn, error) {
77+
dialer := &net.Dialer{}
7478
return ConnectWithDialer(ctx, "", addr, user, password, dbName, dialer.DialContext, options...)
7579
}
7680

7781
// Dialer connects to the address on the named network using the provided context.
7882
type Dialer func(ctx context.Context, network, address string) (net.Conn, error)
7983

80-
// Connect to a MySQL server using the given Dialer.
84+
// ConnectWithDialer to a MySQL server using the given Dialer.
8185
func ConnectWithDialer(ctx context.Context, network string, addr string, user string, password string, dbName string, dialer Dialer, options ...func(*Conn)) (*Conn, error) {
8286
c := new(Conn)
8387

0 commit comments

Comments
 (0)