在 Shell 工作區中管理函式

本頁面說明如何在單一工作區中管理多個 Cloud Functions 設定,以及如何使用 Cloud Code 重新排列 Cloud Run 函式 Explorer。

事前準備

本指南需要已設定的工作區 (至少列出一個設定的 launch.json 檔案)。如要開始使用範例,請參閱建立及部署函式快速入門導覽課程。

在單一工作區中管理多個設定

如要在 launch.json 檔案中新增 Cloud Functions 設定,請按照下列步驟操作:

  1. 按一下「Cloud Code」,然後展開「Cloud Functions」探索工具。

  2. 在 Cloud Run 函式 Explorer 中,按一下滑鼠右鍵點選「WORKSPACE」,然後按一下「Add new cloud function configuration」(新增 Cloud Functions 設定)

  3. 按照提示執行下列動作:

    1. 輸入函式名稱
    2. 選取 Cloud Run functions 環境
    3. 輸入進入點 (要為這個函式呼叫的方法名稱)
    4. 輸入測試輸入內容

    或者,您也可以手動在 launch.json 檔案中輸入這些值:

    {
        "configurations": [
          {
            "name": "Deploy Cloud Function",
            "type": "cloudcode.cloudfunctions",
            "request": "launch",
            "functionName": "hello-world-get",
            "gen": "GEN_2",
            "entryPoint": "helloGet"
          }
        ]
    }
    

    Cloud Run 函式工作區對應於 launch.json 檔案中列出的第一個設定。工作區名稱會反映 launch.json 檔案中列出的第一個設定的 functionName

    {
        "configurations": [
          {
            "name": "Deploy Cloud Function",
            "type": "cloudcode.cloudfunctions",
            "request": "launch",
            "functionName": "hello-world-pub-sub",
            "gen": "GEN_2",
            "entryPoint": "helloPubSub"
          },
          {
            "name": "Deploy Cloud Function",
            "type": "cloudcode.cloudfunctions",
            "request": "launch",
            "functionName": "hello-world-get",
            "gen": "GEN_2",
            "entryPoint": "helloGet"
          }
        ]
    }
    
  4. (選用) 如要從 launch.json 檔案部署其他設定,請將要部署的設定移至 launch.json 檔案頂端,然後按一下「重新整理」重新整理 Cloud Functions 探索器

將 Cloud Run 函式 Explorer 重新排列到 IDE 的檔案 Explorer 中

您可以執行下列操作,將 Cloud Run functions 檔案總管重新排列到 Cloud Shell 的檔案總管中:

  1. 將 Cloud Run 函式 Explorer 拖曳至 Cloud Shell 的檔案 Explorer:

    重新排列 Cloud Functions 探索器

    這樣一來,Cloud Run 函式 Explorer 就會顯示在檔案 Explorer 下方,您可以在同一個窗格中,查看已部署的函式和 Cloud Run 函式工作區,以及專案檔案。

  2. (選用) 如要還原此配置,請將「Cloud Code: Cloud Functions」Explorer 的標題拖曳回「Cloud Code」Explorer。