2017-05-18 18 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

相关问题