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:
242
242
id:password@tcp(your-amazonaws-uri.com:3306)/dbname
243
243
```
244
244
245
+ Google Cloud SQL on App Engine:
246
+ ```
247
+ user@cloudsql(project-id:instance-name)/dbname
248
+ ```
249
+
245
250
TCP using default port (3306) on localhost:
246
251
```
247
252
user: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 (
26
26
// In general the driver is used via the database/sql package.
27
27
type MySQLDriver struct {}
28
28
29
+ type dialFunc func (* config ) (net.Conn , error )
30
+
31
+ var dials map [string ]dialFunc
32
+
29
33
// Open new Connection.
30
34
// See https://github.com/go-sql-driver/mysql#dsn-data-source-name for how
31
35
// the DSN string is formated
@@ -43,8 +47,12 @@ func (d *MySQLDriver) Open(dsn string) (driver.Conn, error) {
43
47
}
44
48
45
49
// 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
+ }
48
56
if err != nil {
49
57
return nil , err
50
58
}
You can’t perform that action at this time.
0 commit comments