Skip to content

Commit df2bedf

Browse files
committed
Specify a custom dial function per config
1 parent 0004702 commit df2bedf

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

connector.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,16 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
8080
dialsLock.RLock()
8181
dial, ok := dials[mc.cfg.Net]
8282
dialsLock.RUnlock()
83-
if ok {
83+
84+
if c.cfg.DialFunc != nil {
85+
dctx := ctx
86+
if mc.cfg.Timeout > 0 {
87+
var cancel context.CancelFunc
88+
dctx, cancel = context.WithTimeout(ctx, c.cfg.Timeout)
89+
defer cancel()
90+
}
91+
mc.netConn, err = c.cfg.DialFunc(dctx, mc.cfg.Addr)
92+
} else if ok {
8493
dctx := ctx
8594
if mc.cfg.Timeout > 0 {
8695
var cancel context.CancelFunc

dsn.go

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type Config struct {
5252
ReadTimeout time.Duration // I/O read timeout
5353
WriteTimeout time.Duration // I/O write timeout
5454
Logger Logger // Logger
55+
DialFunc DialContextFunc // Specify a custom dial function per config instead of using RegisterDialContext
5556

5657
AllowAllFiles bool // Allow all files to be used with LOAD DATA LOCAL INFILE
5758
AllowCleartextPasswords bool // Allows the cleartext client side plugin

0 commit comments

Comments
 (0)