jotting

Google App Engine Flexible for Golang + Cloud SQL for MySQL

Google Cloud Platform

  1. 建立專案
  2. 開啟 App Engine
  3. 開啟 Cloud SQL for MySQL

Setting up Project and Application

  1. 專案要放在 GOPATH
  2. import 自己的資料夾時,路徑要寫完整 "TsiahPng-Golang/AppStart"
  3. 安裝 GAE 套件 go get -u google.golang.org/appengine
  4. Add appengine.Main() 到 ./main.go

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    package main
    import (
    appstart "TsiahPng-Golang/AppStart"

    "google.golang.org/appengine"
    )
    func main() {
    appstart.RouteConfig()
    appengine.Main()
    }
  5. Setting app.yaml file

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    runtime: go
    env: flex

    automatic_scaling:
    min_num_instances: 1
    resources:
    cpu: 1
    memory_gb: 1
    disk_size_gb: 10

    env_variables:
    CLOUD_CONNECTION: "user:password@unix(/cloudsql/INSTANCE_CONNECTION_NAME)/dbname"
    PROJECT_ID: "tsiahpng"
    beta_settings:
    cloud_sql_instances: "INSTANCE_CONNECTION_NAME"

    PS:

Using Cloud SQL for MySQL

  1. https://cloud.google.com/appengine/docs/flexible/go/using-cloud-sql
  2. *important Before you begin → Enable the Cloud SQL API
  3. Download Cloud SDK and Install
  4. gcloud init
  5. gcloud auth login
  6. gcloud auth application-default login
  7. gcloud config set project PROJECT_ID
  8. OPTION: Run the proxy.
    Download
    1
    ./cloud_sql_proxy_x64.exe -instances=<INSTANCE_CONNECTION_NAME>=tcp:3306

Deploy to App Engine

Debug

  • Log
    1. Google App Engine
    2. 服務 → 診斷 → 工具 → 紀錄