diff --git a/connector.go b/connector.go index d567b4e4f..02670e2f2 100644 --- a/connector.go +++ b/connector.go @@ -18,6 +18,10 @@ type connector struct { cfg *Config // immutable private copy. } +func newConnector(cfg *Config) *connector { + return &connector{cfg: cfg} +} + // Connect implements driver.Connector interface. // Connect returns a connection to the database. func (c *connector) Connect(ctx context.Context) (driver.Conn, error) { diff --git a/driver.go b/driver.go index c1bdf1199..cec1079e3 100644 --- a/driver.go +++ b/driver.go @@ -74,10 +74,7 @@ func (d MySQLDriver) Open(dsn string) (driver.Conn, error) { if err != nil { return nil, err } - c := &connector{ - cfg: cfg, - } - return c.Connect(context.Background()) + return newConnector(cfg).Connect(context.Background()) } func init() { @@ -92,7 +89,7 @@ func NewConnector(cfg *Config) (driver.Connector, error) { if err := cfg.normalize(); err != nil { return nil, err } - return &connector{cfg: cfg}, nil + return newConnector(cfg), nil } // OpenConnector implements driver.DriverContext. @@ -101,7 +98,5 @@ func (d MySQLDriver) OpenConnector(dsn string) (driver.Connector, error) { if err != nil { return nil, err } - return &connector{ - cfg: cfg, - }, nil + return newConnector(cfg), nil }