Google Cloud Platform
- 建立專案
- 開啟 App Engine
- 開啟 Cloud SQL for MySQL
Setting up Project and Application
- 專案要放在 GOPATH
- import 自己的資料夾時,路徑要寫完整
"TsiahPng-Golang/AppStart"
- 安裝 GAE 套件
go get -u google.golang.org/appengine
Add
appengine.Main()
到 ./main.go1
2
3
4
5
6
7
8
9
10package main
import (
appstart "TsiahPng-Golang/AppStart"
"google.golang.org/appengine"
)
func main() {
appstart.RouteConfig()
appengine.Main()
}Setting app.yaml file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15runtime: 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:
- resources -> memory_gb:502 server error in Google App Engine Flexible
Using Cloud SQL for MySQL
- https://cloud.google.com/appengine/docs/flexible/go/using-cloud-sql
- *important Before you begin → Enable the Cloud SQL API
- Download Cloud SDK and Install
gcloud init
gcloud auth login
gcloud auth application-default login
gcloud config set project PROJECT_ID
- OPTION: Run the proxy.
Download1
./cloud_sql_proxy_x64.exe -instances=<INSTANCE_CONNECTION_NAME>=tcp:3306
Deploy to App Engine
發行
1
2
3gcloud app deploy
<!-- if use bash with Windows -->
gcloud.cmd app deployPS:
Debug
- Log
- Google App Engine
- 服務 → 診斷 → 工具 → 紀錄