-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Implement Connector interface #671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Would it be possible to implement this in a way that a call back function could be passed in so that the caller could pass in their own connection function. The use case for me would be I want to implement AWS RDS IAM Authentication and the DSN Credentials need to refreshed every 15 min. Something along these lines: func (d MySQLDriver) Connect(c context.Context) (driver.Conn, error) { |
@agruetz You can create own connector which wraps this driver. |
Methane that is absolutely an option as well. I guess the real question is what does this driver plan to do with the connector interface. Seems like it would be a helpful implementation to allow the user of the driver to be able to decide what the connector does and then possibly offer a handful of functions that the driver already contains that could be passed in as well. Either way I would be interested in helping. |
That's what new Connector interface does. So I don't think mysql driver should provide such API. I don't know about AWS authentication. But it will looks like: type CustomConnector {
m sync.Mutex
config *mysql.Config
}
func (c *CustomConnector) Connect(ctx, context.Context) (driver.Conn, error) {
pwd := refreshPassword()
c.m.Lock()
c.config.Passwd = pwd
c.m.Unlock()
return c.config.Connect(ctx)
}
func (c *CustomConnector) Driver() driver.Driver {
return c.config.Driver()
}
You can help by:
|
I think I see what you are driving at. Just have the connecter interface implement a connect function in the driver that just makes a connection to MySQL based on the config vs Parsing a DSN that populates the config. Then the caller can just wrap the mysql driver connector to do whatever special they want to the config. Only down side there is it forces the caller to implement a driver connecter interface to wrap the mysql driver connector interface. Which I guess seems more reasonable because the way I was thinking about it would require them to implement the full conneciton. I will try to take a whack at implementing it. Hopefully it will not be to ugly of an implementation that you guys just laugh at me =). |
@agruetz - I had the same use case as you, and thought I'd try implementing the connector interface outside of the go-sql-driver package and integrating with the AWS Secrets Manager based on @methane's example. I'd be interested in feedback: https://github.com/a-h/go-sql-driver-rds-credentials |
Fixed by #941 |
See golang/go@e6358c7
The text was updated successfully, but these errors were encountered: