LoginSignup
1
1

More than 3 years have passed since last update.

GAE Standard(Go 1.12)でCloud SQL(PostgreSQL)に接続する

Posted at

GAE Standard(Go 1.12)でCloud SQL(PostgreSQL)に接続する

 概要

GAEからCloud SQLに接続する際の情報が公式ドキュメントでは、2019/11/13現在、PythonとJava、Node.jsまでしかなく、Goがどこ行った・・・?
この記事はそんなGo(1.12)でGORMを使って接続する際の情報を記載します。

結論

ホストに
/cloudsql/[Cloud SQLがあるプロジェクトID]:[Cloud SQLがあるゾーン]:[Cloud SQLのインスタンス名]
例:/cloudsql/sampleproject:us-west1:postgresql
を指定すればできます。それを以下で接続する。

db, err = gorm.Open("postgres", fmt.Sprintf("user=%s password=%s host=%s dbname=%s ",
        User,
        Password,
        Host,
        Name))

補足

公式ドキュメントではGo1.11しかサポートしてない記述がありますが、Go1.12も使えます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1