Add default port for mysql connections (#13)

The pq driver already supports this natively, but the mysql driver does not. This commit adds a default port 3306 for mysql connections.
This commit is contained in:
Adrian Macneil 2017-05-04 20:58:39 -07:00 committed by GitHub
parent e393f387b3
commit 9029bbbe3d
2 changed files with 26 additions and 1 deletions

View file

@ -16,6 +16,13 @@ type MySQLDriver struct {
func normalizeMySQLURL(u *url.URL) string {
normalizedURL := *u
normalizedURL.Scheme = ""
// set default port
if normalizedURL.Port() == "" {
normalizedURL.Host = fmt.Sprintf("%s:3306", normalizedURL.Host)
}
// host format required by go-sql-driver/mysql
normalizedURL.Host = fmt.Sprintf("tcp(%s)", normalizedURL.Host)
query := normalizedURL.Query()