@@ -30,25 +30,42 @@ type MySQLDriver struct{}
3030
3131// DialFunc is a function which can be used to establish the network connection.
3232// Custom dial functions must be registered with RegisterDial
33+ //
34+ // Deprecated: users should register a DialContextFunction instead
3335type DialFunc func (addr string ) (net.Conn , error )
3436
37+ // DialContextFund is a function which can be used to establish the network connection.
38+ // Custom dial functions must be registered with RegisterDialContext
39+ type DialContextFunc func (ctx context.Context , addr string ) (net.Conn , error )
40+
3541var (
3642 dialsLock sync.RWMutex
37- dials map [string ]DialFunc
43+ dials map [string ]DialContextFunc
3844)
3945
40- // RegisterDial registers a custom dial function. It can then be used by the
41- // network address mynet(addr), where mynet is the registered new network.
42- // addr is passed as a parameter to the dial function.
43- func RegisterDial (net string , dial DialFunc ) {
46+ // RegisterDialContext registers a custom dial function. It can then be used by the
47+ // network address ` mynet(addr)` , where ` mynet` is the registered new network.
48+ // The current context for the connection and its address is passed to the dial function.
49+ func RegisterDialContext (net string , dial DialContextFunc ) {
4450 dialsLock .Lock ()
4551 defer dialsLock .Unlock ()
4652 if dials == nil {
47- dials = make (map [string ]DialFunc )
53+ dials = make (map [string ]DialContextFunc )
4854 }
4955 dials [net ] = dial
5056}
5157
58+ // RegisterDial registers a custom dial function. It can then be used by the
59+ // network address mynet(addr), where mynet is the registered new network.
60+ // addr is passed as a parameter to the dial function.
61+ //
62+ // Deprecated: users should call RegisterDialContext instead
63+ func RegisterDial (network string , dial DialFunc ) {
64+ RegisterDialContext (network , func (_ context.Context , addr string ) (net.Conn , error ) {
65+ return dial (addr )
66+ })
67+ }
68+
5269// Open new Connection.
5370// See https://github.com/go-sql-driver/mysql#dsn-data-source-name for how
5471// the DSN string is formatted
0 commit comments