From 10339ddc0ad003634f447d92547195bea02c544d Mon Sep 17 00:00:00 2001 From: dvilaverde Date: Fri, 26 Apr 2024 16:42:52 -0400 Subject: [PATCH] Allow connect with context in order to provide configurable connect timeouts --- client/conn.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/conn.go b/client/conn.go index 1db021762..9d7014951 100644 --- a/client/conn.go +++ b/client/conn.go @@ -69,15 +69,19 @@ func Connect(addr string, user string, password string, dbName string, options . ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() - dialer := &net.Dialer{} + return ConnectWithContext(ctx, addr, user, password, dbName, options...) +} +// ConnectWithContext to a MySQL addr using the provided context. +func ConnectWithContext(ctx context.Context, addr string, user string, password string, dbName string, options ...func(*Conn)) (*Conn, error) { + dialer := &net.Dialer{} return ConnectWithDialer(ctx, "", addr, user, password, dbName, dialer.DialContext, options...) } // Dialer connects to the address on the named network using the provided context. type Dialer func(ctx context.Context, network, address string) (net.Conn, error) -// Connect to a MySQL server using the given Dialer. +// ConnectWithDialer to a MySQL server using the given Dialer. func ConnectWithDialer(ctx context.Context, network string, addr string, user string, password string, dbName string, dialer Dialer, options ...func(*Conn)) (*Conn, error) { c := new(Conn)