設定開發環境

安裝下列工具,藉此在 Google Cloud 上設定適當的 Go 應用程式開發及部署環境。

安裝 Go

  1. 如要安裝 Go,請參閱 Go 入門指南

  2. 確認您已安裝最新版的 Go:

    go version
    

安裝編輯器

如要盡可能提高 Go 開發效率,這些熱門的編輯器外掛程式和 IDE 提供下列功能:

  • 完全整合的除錯功能
  • 語法醒目顯示
  • 補全程式碼

安裝 Google Cloud CLI

Google Cloud CLI 是一組適用於 Google Cloud的工具,其中包含 gcloudbq 指令列工具,可從指令列存取 Compute Engine、Cloud Storage、BigQuery 和其他服務。您可以利用這些工具進行互動操作,或是在自動化指令碼中執行這些工具。

例如,如要使用 main 套件在 App Engine 部署 Go 網頁應用程式,請執行下列指令:

gcloud app deploy

如要安裝 gcloud CLI,請參閱「安裝 gcloud CLI」。

安裝 Go 適用的 Cloud 用戶端程式庫

Go 開發人員常運用 Go 適用的 Cloud 用戶端程式庫整合各項Google Cloud 服務,例如 Datastore 和 Cloud Storage。

舉例來說,如要安裝個別 API 的套件 (例如 Cloud Storage API),請按照下列步驟操作:

  1. 如果專案已有 Go 模組,請切換至該目錄。否則請建立模組:

    go mod init YOUR_MODULE_NAME
    

    YOUR_MODULE_NAME 替換為新模組的名稱。

  2. 在專案中使用 Cloud Storage 套件:

    go get cloud.google.com/go/storage
    

設定驗證方法

如要在本機開發環境中使用 Cloud 用戶端程式庫,請設定應用程式預設憑證。

If you're using a local shell, then create local authentication credentials for your user account:

gcloud auth application-default login

You don't need to do this if you're using Cloud Shell.

If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

詳情請參閱「驗證以使用用戶端程式庫」。

安裝其他實用工具

如需 Go 工具和程式庫的完整清單,請參閱 GitHub 上的 Go 架構、程式庫和軟體清單

後續步驟