Skip to content

Create a mysql.Connect API. #1045

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 2 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
12 changes: 12 additions & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,15 @@ func (d MySQLDriver) OpenConnector(dsn string) (driver.Connector, error) {
cfg: cfg,
}, nil
}

// Connect connects to MySQL server.
// You can use this function to create custom connector which dynamically
// change the config. The cfg object must not be changed during calling
// this function.
func Connect(ctx context.Context, cfg *Config) (driver.Conn, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a pointer here if it's sensitive to concurrent changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because shallow copy of the config object is not a right way to copy config object.

connector, err := NewConnector(cfg)
if err != nil {
return nil, err
}
return connector.Connect(ctx)
}