Skip to content

Commit

Permalink
Specify a custom dial function per config
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronjheng committed Dec 15, 2023
1 parent 0004702 commit df2bedf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
dialsLock.RLock()
dial, ok := dials[mc.cfg.Net]
dialsLock.RUnlock()
if ok {

if c.cfg.DialFunc != nil {
dctx := ctx
if mc.cfg.Timeout > 0 {
var cancel context.CancelFunc
dctx, cancel = context.WithTimeout(ctx, c.cfg.Timeout)
defer cancel()
}
mc.netConn, err = c.cfg.DialFunc(dctx, mc.cfg.Addr)
} else if ok {
dctx := ctx
if mc.cfg.Timeout > 0 {
var cancel context.CancelFunc
Expand Down
1 change: 1 addition & 0 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Config struct {
ReadTimeout time.Duration // I/O read timeout
WriteTimeout time.Duration // I/O write timeout
Logger Logger // Logger
DialFunc DialContextFunc // Specify a custom dial function per config instead of using RegisterDialContext

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

0 comments on commit df2bedf

Please sign in to comment.