Skip to content

Commit fc2a465

Browse files
committed
add GCLOUD_SQL_INSTANCE option while still using postgres url
1 parent 586a8e2 commit fc2a465

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cSpell.enabled": false
3+
}

datastore.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,13 @@ func getDBConnection(store *Datastore) *runner.DB {
176176
host = store.Settings.Get("GCLOUD_SQL_INSTANCE")
177177
}
178178

179-
store.Logger.Info("dbname=" + dbName + " user=" + username + " host=" + host + " port=" + port + " sslmode=disable") // no pass
179+
dbStr := "dbname=" + dbName + " user=" + username + " host=" + host
180+
if port != "" {
181+
dbStr += " port=" + port
182+
}
183+
store.Logger.Info(dbStr)
180184

181-
db, _ := sql.Open("postgres", "dbname="+dbName+" user="+username+" password="+pass+" host="+host+" port="+port+" sslmode=disable")
185+
db, _ := sql.Open("postgres", dbStr+" password="+pass+" sslmode=disable ") // pass goes last
182186
err = db.Ping()
183187
if err != nil {
184188
store.Logger.Error(err)

0 commit comments

Comments
 (0)