Source File
	driver.go
Belonging Package
	github.com/go-sql-driver/mysql
// Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved.//// This Source Code Form is subject to the terms of the Mozilla Public// License, v. 2.0. If a copy of the MPL was not distributed with this file,// You can obtain one at http://mozilla.org/MPL/2.0/.// Package mysql provides a MySQL driver for Go's database/sql package.//// The driver should be used via the database/sql package://// import "database/sql"// import _ "github.com/go-sql-driver/mysql"//// db, err := sql.Open("mysql", "user:password@/dbname")//// See https://github.com/go-sql-driver/mysql#usage for detailspackage mysqlimport ()// MySQLDriver is exported to make the driver directly accessible.// In general the driver is used via the database/sql package.type MySQLDriver struct{}// DialFunc is a function which can be used to establish the network connection.// Custom dial functions must be registered with RegisterDial//// Deprecated: users should register a DialContextFunc insteadtype DialFunc func(addr string) (net.Conn, error)// DialContextFunc is a function which can be used to establish the network connection.// Custom dial functions must be registered with RegisterDialContexttype DialContextFunc func(ctx context.Context, addr string) (net.Conn, error)var (dialsLock sync.RWMutexdials map[string]DialContextFunc)// RegisterDialContext registers a custom dial function. It can then be used by the// network address mynet(addr), where mynet is the registered new network.// The current context for the connection and its address is passed to the dial function.func ( string, DialContextFunc) {dialsLock.Lock()defer dialsLock.Unlock()if dials == nil {dials = make(map[string]DialContextFunc)}dials[] =}// RegisterDial registers a custom dial function. It can then be used by the// network address mynet(addr), where mynet is the registered new network.// addr is passed as a parameter to the dial function.//// Deprecated: users should call RegisterDialContext insteadfunc ( string, DialFunc) {RegisterDialContext(, func( context.Context, string) (net.Conn, error) {return ()})}// Open new Connection.// See https://github.com/go-sql-driver/mysql#dsn-data-source-name for how// the DSN string is formattedfunc ( MySQLDriver) ( string) (driver.Conn, error) {, := ParseDSN()if != nil {return nil,}:= &connector{cfg: ,}return .Connect(context.Background())}func init() {sql.Register("mysql", &MySQLDriver{})}// NewConnector returns new driver.Connector.func ( *Config) (driver.Connector, error) {= .Clone()// normalize the contents of cfg so calls to NewConnector have the same// behavior as MySQLDriver.OpenConnectorif := .normalize(); != nil {return nil,}return &connector{cfg: }, nil}// OpenConnector implements driver.DriverContext.func ( MySQLDriver) ( string) (driver.Connector, error) {, := ParseDSN()if != nil {return nil,}return &connector{cfg: ,}, nil}
|  | The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |