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
database/sql: mysql TLS support for Open #5737
Labels
Comments
For the MySQL driver, I accomplished it like this: db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom") db.Driver().(mysql.TLSConfig).SetTLSConfig("custom", &tls.Config{ RootCAs: rootCAs, Certificates: clientCerts, }) (Pull request here: go-sql-driver/mysql#101 The solution is somewhat a hack. Issue #4804 has a discussion whether or not to open a connection on the Open function. If it did, this patch wouldn't work. So there are several problems: - "Open" shouldn't be called Open, if it will not actually Open any connections. - "Open" is too restrictive. It feels very PHP like, not Go like - which btw, I moved away from PHP for a reason. There are also other assumptions made by database/sql. The prepared statements interface would seem to suggest that only indexed parameters "?" are allowed. What about :named parameters? |
Labels changed: added priority-later, removed priority-triage. Owner changed to @bradfitz. Status changed to Accepted. |
IMO it's inflexible because you can only pass a string into the driver. If sql.Open had opened a connection (which could have been the case, see issue #4804) the patch I presented would have been impossible. The second argument should allow you to pass anything required by the driver - either a map[string]interface{} or just an interface{}. One way you could fix this is by changing the second argument to an interface{}. That would allow a string to be passed as it is now, and allow certain drivers to accept other things, like maps. |
Your driver can provide: package yourdriver func Open(host, username, password string, wantTLS bool) (*DB, error) And internally, it can marshal host/user/pass/wantTLS into a URL-encoded string (or gob, or proto, or whatever) and pass that to DB.Open, and then your driver will URL-decode/whatever it. |
I'm not sure I would want to marshal/unmarshal tls.Config to/from a string. Although I suppose I could have a unique string that would have a key to a map that contained it... Still, I feel that is more complicated than simply allowing the second argument to be an interface{} :). Oh well. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: