File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import (
2020 "database/sql"
2121 "database/sql/driver"
2222 "net"
23+ "sync"
2324)
2425
2526// watcher interface is used for context support (From Go 1.8)
@@ -35,12 +36,17 @@ type MySQLDriver struct{}
3536// Custom dial functions must be registered with RegisterDial
3637type DialFunc func (addr string ) (net.Conn , error )
3738
38- var dials map [string ]DialFunc
39+ var (
40+ dialsLock sync.RWMutex
41+ dials map [string ]DialFunc
42+ )
3943
4044// RegisterDial registers a custom dial function. It can then be used by the
4145// network address mynet(addr), where mynet is the registered new network.
4246// addr is passed as a parameter to the dial function.
4347func RegisterDial (net string , dial DialFunc ) {
48+ dialsLock .Lock ()
49+ defer dialsLock .Unlock ()
4450 if dials == nil {
4551 dials = make (map [string ]DialFunc )
4652 }
@@ -66,7 +72,10 @@ func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
6672 mc .parseTime = mc .cfg .ParseTime
6773
6874 // Connect to Server
69- if dial , ok := dials [mc .cfg .Net ]; ok {
75+ dialsLock .RLock ()
76+ dial , ok := dials [mc .cfg .Net ]
77+ dialsLock .RUnlock ()
78+ if ok {
7079 mc .netConn , err = dial (mc .cfg .Addr )
7180 } else {
7281 nd := net.Dialer {Timeout : mc .cfg .Timeout }
You can’t perform that action at this time.
0 commit comments