Skip to content

Commit

Permalink
storage/appengine: update CloudSQL connection string
Browse files Browse the repository at this point in the history
Connections are handled slightly differently in the go111 runtime.

Change-Id: I289c3333db2e1b164198bea999c8b085f72618c1
Reviewed-on: https://go-review.googlesource.com/c/perf/+/191478
Reviewed-by: Katie Hockman <katie@golang.org>
  • Loading branch information
andybons committed Aug 23, 2019
1 parent f6bfb0e commit ecb187b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion storage/appengine/app.go
Expand Up @@ -33,9 +33,15 @@ func connectDB() (*db.DB, error) {
user = mustGetenv("CLOUDSQL_USER")
password = os.Getenv("CLOUDSQL_PASSWORD") // NOTE: password may be empty
dbName = mustGetenv("CLOUDSQL_DATABASE")
socket = os.Getenv("CLOUDSQL_SOCKET_PREFIX")
)

return db.OpenSQL("mysql", fmt.Sprintf("%s:%s@cloudsql(%s)/%s?interpolateParams=true", user, password, connectionName, dbName))
// /cloudsql is used on App Engine.
if socket == "" {
socket = "/cloudsql"
}

return db.OpenSQL("mysql", fmt.Sprintf("%s:%s@unix(%s/%s)/%s", user, password, socket, connectionName, dbName))
}

func mustGetenv(k string) string {
Expand Down

0 comments on commit ecb187b

Please sign in to comment.