删除分类

删除现有分类。

代码示例

转到

在尝试此示例之前,请按照《Data Catalog 快速入门:使用客户端库》中的 Go 设置说明进行操作。如需了解详情,请参阅 Data Catalog Go API 参考文档

import (
	"context"
	"fmt"

	datacatalog "cloud.google.com/go/datacatalog/apiv1beta1"
	datacatalogpb "google.golang.org/genproto/googleapis/cloud/datacatalog/v1beta1"
)

// deleteTaxonomy removes an existing taxonomy resource.
func deleteTaxonomy(taxonomyID string) error {
	// taxonomyID := "projects/myproject/locations/us/taxonomies/1234"
	ctx := context.Background()
	policyClient, err := datacatalog.NewPolicyTagManagerClient(ctx)
	if err != nil {
		return fmt.Errorf("datacatalog.NewPolicyTagManagerClient: %v", err)
	}
	defer policyClient.Close()

	req := &datacatalogpb.DeleteTaxonomyRequest{
		Name: taxonomyID,
	}
	return policyClient.DeleteTaxonomy(ctx, req)
}

Node.js

在尝试此示例之前,请按照《Data Catalog 快速入门:使用客户端库》中的 Node.js 设置说明进行操作。如需了解详情,请参阅 Data Catalog Node.js API 参考文档

// Import the Google Cloud client library.
const {PolicyTagManagerClient} = require('@google-cloud/datacatalog').v1;
const policyTagManager = new PolicyTagManagerClient();

async function deleteTaxonomy() {
  /**
   * TODO(developer): Uncomment the following line before running the sample.
   */
  // const projectId = 'my_project'; // Google Cloud Platform project
  // const location = 'us';
  // const taxonomy = 'my_existing_taxonomy';
  // const taxonomyName = `projects/${projectId}/locations/${location}/taxonomies/${taxonomy}`;

  const request = {
    name: taxonomyName,
  };

  try {
    await policyTagManager.deleteTaxonomy(request);
    console.log(`Deleted taxonomy: ${taxonomyName}`);
  } catch (e) {
    console.error(e);
    process.exitCode = 1;
  }
}

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器