File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -242,6 +242,11 @@ TCP on a remote host, e.g. Amazon RDS:
242242id:password@tcp(your-amazonaws-uri.com:3306)/dbname
243243```
244244
245+ Google Cloud SQL on App Engine:
246+ ```
247+ user@cloudsql(project-id:instance-name)/dbname
248+ ```
249+
245250TCP using default port (3306) on localhost:
246251```
247252user:password@tcp/dbname&charset=utf8mb4,utf8&sys_var=esc%40ped
Original file line number Diff line number Diff line change 1+ // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2+ //
3+ // Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved.
4+ //
5+ // This Source Code Form is subject to the terms of the Mozilla Public
6+ // License, v. 2.0. If a copy of the MPL was not distributed with this file,
7+ // You can obtain one at http://mozilla.org/MPL/2.0/.
8+
9+ // +build appengine
10+
11+ package mysql
12+
13+ import (
14+ "appengine/cloudsql"
15+ "net"
16+ )
17+
18+ func init () {
19+ if dials == nil {
20+ dials = make (map [string ]dialFunc )
21+ }
22+ dials ["cloudsql" ] = func (cfg * config ) (net.Conn , error ) {
23+ return cloudsql .Dial (cfg .addr )
24+ }
25+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ import (
2626// In general the driver is used via the database/sql package.
2727type MySQLDriver struct {}
2828
29+ type dialFunc func (* config ) (net.Conn , error )
30+
31+ var dials map [string ]dialFunc
32+
2933// Open new Connection.
3034// See https://github.com/go-sql-driver/mysql#dsn-data-source-name for how
3135// the DSN string is formated
@@ -43,8 +47,12 @@ func (d *MySQLDriver) Open(dsn string) (driver.Conn, error) {
4347 }
4448
4549 // Connect to Server
46- nd := net.Dialer {Timeout : mc .cfg .timeout }
47- mc .netConn , err = nd .Dial (mc .cfg .net , mc .cfg .addr )
50+ if dial , ok := dials [mc .cfg .net ]; ok {
51+ mc .netConn , err = dial (mc .cfg )
52+ } else {
53+ nd := net.Dialer {Timeout : mc .cfg .timeout }
54+ mc .netConn , err = nd .Dial (mc .cfg .net , mc .cfg .addr )
55+ }
4856 if err != nil {
4957 return nil , err
5058 }
You can’t perform that action at this time.
0 commit comments