在 Shell 工作区中管理函数

本页介绍了如何管理多个 Cloud Functions 配置 如何使用单个工作区以及如何重新排列 Cloud Functions Explorer, Cloud Code

准备工作

本指南要求必须已设置工作区(包含位于launch.json 至少列出一项配置)。要开始使用示例,请参阅 创建和部署函数 快速入门。

在一个工作区中管理多个配置

如需将新的 Cloud Function 配置添加到 launch.json 文件中,请按照下列步骤操作: 具体步骤:

  1. 点击 Cloud Code,然后展开 Cloud Functions Explorer。

  2. 在 Cloud Functions Explorer 中 右键点击工作区,然后点击 添加新的 Cloud Functions 函数配置

  3. 按照提示操作并执行以下操作:

    1. 输入函数名称
    2. 选择 Cloud 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 Functions 工作区对应于 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 文件顶部的配置, 点击 refresh 刷新 Cloud Functions Explorer

将 Cloud Functions Explorer 重新排列到 IDE 的文件资源管理器中

您可以将 Cloud Functions Explorer 重新排列为 Cloud Shell 的文件资源管理器:

  1. 将 Cloud Functions Explorer 拖到 Cloud Shell 的文件资源管理器:

    重新排列了 Cloud Functions Explorer

    这种布局方式会将您的 Cloud Functions Explorer 显示在 以便你能够查看已部署的函数 Cloud Functions 工作区与项目文件位于同一窗格中。

  2. (可选)要撤消此排列方式,请拖动 Cloud Code: Cloud Functions Explorer 返回 Cloud Code