2017-05-18 19 views

回答

3

這是可能的。

免責聲明:我還沒有嘗試過實際做到這一點,所以在接下來的內容中可能會出現拼寫錯誤/小錯誤。另外,我想向您保證,CloudSQL文檔團隊瞭解並正在爲其他語言(包括Go)添加示例。

Under the Guts AppEngine Flex爲您運行CloudSQL proxy,您的代碼通過通常的驅動程序使用unix套接字連接到CloudSQL。

所以雖然沒有Go的例子,但應該相當容易。假設你使用標準的Go的SQL圖書館和閱讀https://godoc.org/github.com/lib/pq看起來像你需要在你的代碼是這樣的:

db, err := sql.Open("postgres", "user=username password=password host=/cloudsql/INSTANCE_CONNECTION_NAME dbname=databasename") 

或者,如果您使用不同的格式或庫,只要確保主機參數指定/cloudsql/INSTANCE_CONNECTION_NAME

此外,請務必遵循https://cloud.google.com/appengine/docs/flexible/python/using-cloud-sql-postgres的所有非Python特定步驟。

PS:下面是Django的示例:Postgres settings for Django on Google App Engine Flexi

相關問題