Closed XiaoYiXiaoYang closed 4 months ago
use custom configuration
config, err := go_ora.ParseConfig(`yours DSN string`)
// pass object that support dialer context
config.Dialer = new_object
go_ora.RegisterConfig(config)
db, err := sql.Open("oracle", "")
the definition of DilerContext
type DialerContext interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
next release (v2.8.19) you can do the following
config, err := go_ora.ParseConfig(`yours DSN string`)
config.RegisterDial(func(ctx context.Context, network, address string) (net.Conn, error) {
// your custom dial code
})
go_ora.RegisterConfig(config)
db, err := sql.Open("oracle", "")
thanks~~
connector := go_ora.NewConnector(connStr)
connector.(*go_ora.OracleConnector).Dialer(new_obj)
db := sql.OpenDB(connector)
defer db.Close()
this method can worked for me correctly.
next release (v2.8.19) you can do the following
config, err := go_ora.ParseConfig(`yours DSN string`) config.RegisterDial(func(ctx context.Context, network, address string) (net.Conn, error) { // your custom dial code }) go_ora.RegisterConfig(config) db, err := sql.Open("oracle", "")
@sijms when i use this method,it doesn't work correctly? can you help me for a review?
func (connector *OracleConnector) Connect(ctx context.Context) (driver.Conn, error) {
// code
conn, err := NewConnection(connector.connectString, connector.drv.connOption)
conn.connOption.Dialer = connector.dialer
// code
}
my register dial will be overwritten by connector's dialer
sorry for late replay I fix in next release
when i use "github.com/lib/pq" as sql driver to connect to postgressql i can use func DialOpen(d Dialer, dsn string) (_ driver.Conn, err error) method to connect to db with my custom dialer
and i suggest "github.com/denisenkom/go-mssqldb" need a same one
and "github.com/go-sql-driver/mysql" have a similar method to use my own custom dialer, it is func RegisterDial(network string, dial DialFunc)