forked from ngrok/sqlmw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnector.go
executable file
·45 lines (35 loc) · 935 Bytes
/
connector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// +build go1.10
package sqlmw
import (
"context"
"database/sql/driver"
)
type wrappedConnector struct {
parent driver.Connector
driverRef *wrappedDriver
}
var (
_ driver.Connector = wrappedConnector{}
)
func (c wrappedConnector) Connect(ctx context.Context) (conn driver.Conn, err error) {
conn, err = c.driverRef.intr.ConnectorConnect(ctx, c.parent)
if err != nil {
return nil, err
}
return wrappedConn{intr: c.driverRef.intr, parent: conn}, nil
}
func (c wrappedConnector) Driver() driver.Driver {
return c.driverRef
}
// dsnConnector is a fallback connector placed in position of wrappedConnector.parent
// when given Driver does not comply with DriverContext interface.
type dsnConnector struct {
dsn string
driver driver.Driver
}
func (t dsnConnector) Connect(_ context.Context) (driver.Conn, error) {
return t.driver.Open(t.dsn)
}
func (t dsnConnector) Driver() driver.Driver {
return t.driver
}