@@ -3,8 +3,6 @@ package sa
33import (
44 "database/sql"
55 "fmt"
6- "net/url"
7- "strings"
86 "time"
97
108 "github.com/go-sql-driver/mysql"
@@ -22,12 +20,6 @@ import (
2220func NewDbMap (dbConnect string , maxOpenConns int ) (* gorp.DbMap , error ) {
2321 var err error
2422 var config * mysql.Config
25- if strings .HasPrefix (dbConnect , "mysql+tcp://" ) {
26- dbConnect , err = recombineCustomMySQLURL (dbConnect )
27- if err != nil {
28- return nil , err
29- }
30- }
3123
3224 config , err = mysql .ParseDSN (dbConnect )
3325 if err != nil {
@@ -104,49 +96,6 @@ func adjustMySQLConfig(conf *mysql.Config) *mysql.Config {
10496 return conf
10597}
10698
107- // recombineCustomMySQLURL transforms the legacy database URLs into the
108- // URL-like strings expected by the mysql database driver.
109- //
110- // In the past, changes to the connection string were achieved by passing it
111- // into url.Parse and editing the query string that way, so the string had to
112- // be a valid URL. The mysql driver needs the Host data to be wrapped in
113- // "tcp()" but url.Parse will escape the parentheses and the mysql driver
114- // doesn't understand them. So, we couldn't have "tcp()" in the configs, but
115- // couldn't leave it out before passing it to the mysql driver. Similarly, the
116- // driver needs the password and username unescaped. The compromise was to do
117- // the leg work if the connection string's scheme is a fake one called
118- // "mysql+tcp://".
119- //
120- // Upon the addition of
121- // https://godoc.org/github.com/go-sql-driver/mysql#Config, this was no longer
122- // necessary, as the changes could be made on the decomposed struct version of
123- // the connection url. This method converts the old format into the format
124- // expected by the library.
125- func recombineCustomMySQLURL (dbConnect string ) (string , error ) {
126- dbConnect = strings .TrimSpace (dbConnect )
127- dbURL , err := url .Parse (dbConnect )
128- if err != nil {
129- return "" , err
130- }
131-
132- if dbURL .Scheme != "mysql+tcp" {
133- format := "given database connection string was not a mysql+tcp:// URL, was %#v"
134- return "" , fmt .Errorf (format , dbURL .Scheme )
135- }
136-
137- user := dbURL .User .Username ()
138- passwd , hasPass := dbURL .User .Password ()
139- dbConn := ""
140- if user != "" {
141- dbConn = url .QueryEscape (user )
142- }
143- if hasPass {
144- dbConn += ":" + passwd
145- }
146- dbConn += "@tcp(" + dbURL .Host + ")"
147- return dbConn + dbURL .EscapedPath () + "?" + dbURL .RawQuery , nil
148- }
149-
15099// SetSQLDebug enables GORP SQL-level Debugging
151100func SetSQLDebug (dbMap * gorp.DbMap , log blog.Logger ) {
152101 dbMap .TraceOn ("SQL: " , & SQLLogger {log })
0 commit comments