Skip to content

Commit

Permalink
Allow connect with context in order to provide configurable connect t…
Browse files Browse the repository at this point in the history
…imeouts
  • Loading branch information
dvilaverde committed Apr 26, 2024
1 parent 5427a8d commit 10339dd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 10339dd

Please sign in to comment.