Skip to content

Implement Connector interface #705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Addresses feedback
  • Loading branch information
anthonygruetzmacher committed Feb 22, 2018
commit bc89eaee2eaaeee95015bb9fe157a19d4fe601ea
23 changes: 8 additions & 15 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,18 @@ func RegisterDial(net string, dial DialFunc) {
}

//Open a new Connection
func connectServer(mc *mysqlConn) error {
func connectServer(cxt context.Context, mc *mysqlConn) error {
var err error
// Connect to Server
if dial, ok := dials[mc.cfg.Net]; ok {
mc.netConn, err = dial(mc.cfg.Addr)
} else {
nd := net.Dialer{Timeout: mc.cfg.Timeout}
mc.netConn, err = nd.Dial(mc.cfg.Net, mc.cfg.Addr)
if cxt == nil {
mc.netConn, err = nd.Dial(mc.cfg.Net, mc.cfg.Addr)
} else {
mc.netConn, err = nd.DialContext(cxt, mc.cfg.Net, mc.cfg.Addr)
}
}
if err != nil {
return err
Expand Down Expand Up @@ -176,22 +180,11 @@ func (c MySQLConnector) Connect(cxt context.Context) (driver.Conn, error) {
return nil, cxt.Err()
default:
//Connect to the server and setting the connection settings
err = connectServer(mc)
err = connectServer(cxt, mc)
if err != nil {
return nil, err
}
}

//Check to see if there was a canelation during creating the connection
select {
case <-cxt.Done():
err = mc.Close()
if err != nil {
return nil, errors.New(cxt.Err().Error() + ":" + err.Error())
}

return nil, cxt.Err()
default:
return mc, nil
}
}
Expand Down Expand Up @@ -224,7 +217,7 @@ func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
}
mc.parseTime = mc.cfg.ParseTime

err = connectServer(mc)
err = connectServer(nil, mc)
// Connect to Server
if err != nil {
return nil, err
Expand Down