在 App Engine 標準環境中建立 Go 1.11 應用程式
區域 ID
REGION_ID
是 Google 根據您在建立應用程式時選取的地區所指派的縮寫代碼。此代碼不對應至國家/地區或省份,即使部分區域 ID 可能與常用的國家/地區和省份代碼相似。如果是 2020 年 2 月後建立的應用程式,App Engine 網址會包含 REGION_ID.r
。如果是這段時間前建立的現有應用程式,網址可選擇是否包含地區 ID。
進一步瞭解區域 ID。
本頁面說明如何部署基本的 App Engine 應用程式,讓畫面顯示簡短訊息。如需深入瞭解 App Engine 上的 Go,請參閱建構應用程式相關說明。
App Engine 是否為適合您的運算選項?請參考在 Google Cloud上託管應用程式的選項,瞭解其他選擇,評估您的需求。
費用
操作本指南步驟並不會產生任何費用,而單獨執行這個範例應用程式也不會超過您的免費配額。
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Build API.
-
Install the Google Cloud CLI.
-
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
-
如要初始化 gcloud CLI,請執行下列指令:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Build API.
-
Install the Google Cloud CLI.
-
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
-
如要初始化 gcloud CLI,請執行下列指令:
gcloud init
使用您的專案將 App Engine 應用程式初始化,然後選擇地區:
gcloud app create --project=[YOUR_PROJECT_ID]
收到系統提示時,選取 App Engine 應用程式的存放地區。
安裝下列必要項目:
執行下列指令,安裝 gcloud 元件 (包括 Go 1.11 適用的 App Engine 擴充功能):
gcloud components install app-engine-go
請執行
gcloud app describe
指令。在 Google Cloud 控制台中開啟 App Engine 資訊主頁。區域會顯示在頁面頂端附近。
-
git clone https://github.com/GoogleCloudPlatform/golang-samples
您也可以使用 zip 格式下載範例,然後解壓縮。
變更為包含範例程式碼的目錄:
cd golang-samples/appengine/go11x/helloworld/
透過從
golang-samples/appengine/go11x/helloworld
目錄執行下列指令,在 App Engine 上部署 Hello World 應用程式:gcloud app deploy
在
https://PROJECT_ID.REGION_ID.r.appspot.com
查看上線的應用程式:gcloud app browse
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
其他必要條件
App Engine 位置
App Engine 具有「地區性」,這表示執行應用程式的基礎架構位於特定地區,且由 Google 代管,可為該地區內的所有區域提供備援功能。
選擇應用程式的執行地區時,請將您在延遲時間、可用性和耐用性方面的要求,做為主要考量。一般來說,您可以選擇距離您應用程式使用者最近的地區,但您也應該考慮 App Engine 的可用位置,以及應用程式使用的其他Google Cloud 產品和服務的位置。如果跨多個位置使用服務,可能會影響應用程式的延遲時間和定價。
應用程式的地區設定完成後即無法更改。
如果您已建立 App Engine 應用程式,可以透過下列方式查看其區域:
本快速入門導覽課程假設您已熟悉 Go 程式設計語言,並且已在系統上安裝 Go。
下載 Hello World 應用程式
我們建立了 Go 適用的簡易 Hello World 應用程式,方便您快速瞭解如何在 Google Cloud Platform 中部署應用程式。請依照下列步驟將 Hello World 下載到本機電腦。
如要下載範例應用程式並前往應用程式目錄:
將 Hello World 部署至 App Engine
「Hello, World!」訊息目前是由 App Engine 執行個體上執行的網路伺服器提供。
恭喜!您已成功在 App Engine 上部署 Go 網路服務!
清除所用資源
如要繼續瞭解 App Engine,您可以保留 Google Cloud 專案並按照建構應用程式的說明進行操作。
或者,您可以刪除 Google Cloud 專案,這樣系統就會停止對該專案使用的所有資源收取費用。
後續步驟
現在您已經有在 App Engine 上部署網路服務的經驗,接著請參閱建構應用程式的相關說明,深入瞭解 App Engine 上的 Go。